我有以下型号:
class UserProfile(models.Model):
mobileNumber = models.BigIntegerField(primary_key=True)
authKey = models.CharField(max_length=300,null=False,blank=False)
creationDateTime = models.DateTimeField(auto_now_add=True)
lastUpdateDateTime = models.DateTimeField(auto_now=True)
Run Code Online (Sandbox Code Playgroud)
串行:
class UserProfileSerializer(serializers.ModelSerializer):
class Meta:
model = UserProfile
fields = ('mobileNumber','authKey')
Run Code Online (Sandbox Code Playgroud)
如果userprofile模型已经有一个移动号码XX44,并且如果我尝试使用带有json {'mobileNumber'的UserProfileSerializer序列化:'ux44,'authKey':u'ggsdsagldaslhdkjashdjkashdjkahsdkjah'}我收到以下错误:
{'mobileNumber': [u'User profile with this MobileNumber already exists.']}
Run Code Online (Sandbox Code Playgroud)
因为正在为序列化器字段运行模型验证.
如何停止执行mobileNumber的模型字段验证.我在序列化程序中尝试了validate和validate_mobileNumber方法,但它们仍在执行模型验证.
django django-models django-forms django-validation django-rest-framework
我想使用django管理界面来显示模型中的数据聚合.例如:模型有以下字段[员工姓名,工资,月份]我希望聚合表包含字段[month,total_salary_paid,cumulative_of_month_salaries_paid].我该怎么做呢 ??我搜索过互联网但没有找到任何办法.任何参考或指导都会有所帮助
django django-models django-admin django-modeladmin django-admin-tools