Overriding a Field attribute in a proxy model is not allowed.
Hello, I'm currently working with an app that i would not like to modify. This app contains 2 Models, basically : (i took off some code to make it clearer) ``` class Invoice(models.Model): [...] a bunch of attributes [...] lines = generic.GenericRelation(Line) [...] all the class methods [...] class Line(models.Model): content_type [...] [...] a bunch of attributes [...] product = models.ForeignKey(Product) price = models.DecimalField() quantity = models.IntegerField() [...] all the class methods [...] ``` I would like to add only method computing the values of these models to use it elsewhere (another app). So no table in database, need to add methods and do not want to modifiy the original class, the documentation seems to indicate the model proxy. So i'm going with something like this in a different app : ``` class PackingList(Invoice): lines = generic.GenericRelation(PackingListLine) def get_number_of_boxes(self): total = 0 for line in self.lines.all(): total += line.get_number_of_boxes() return total class Meta: proxy = True class PackingListLine(Line): def get_number_of_boxes(self): if self.product.quantity_per_box: return self.quantity / self.product.quantity_per_box class Meta: proxy = True ``` But Django raise a beautiful ```django.core.exceptions.FieldError: Proxy model 'PackingList' contains model fields.```. Normal ! It is clearly specified in the docs, it is forbidden to override a field attribute in a Django Model. So i understand the need to restrict the usage of these manipulation to not break the framework internal mechanisms, but i don't know in this case which other approach would be best (Minimal model with one2one relationship ? everything in a view class ? separate my code in a different class/file that i would call individually ? triggers ? make an intermediate class that would get the instance ?). My question is, what is the clean way to code this ? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/4QK6OGtwP5cJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Localization with thousand separator makes foreign key id invalid in forms
Hello, With localization and thousand separator active, my foreign keys ids are rendered with a thousand separator in django forms and give me an invalid field during validation. in settings.py: USE_L10N = True USE_THOUSAND_SEPARATOR = True example : Company something something with the french localization For now i just override the template django/forms/widgets/select_option.html with the safe filter : {{ widget.label }} I think it would be nicer to have the safe filter in the default template from django repository. Now i file it here to see if people consider it as a bug or if this behavior is considered as normal and if others get this problem as well, before filing a ticket on djangoproject.com. Regards, Thomas. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/945045e0-d7bf-42ec-983f-b75b78ca86b9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Localization with thousand separator makes foreign key id invalid in forms
Hello Simon, I confirm, updated the project to 1.11.1 and it is solved. Thanks for taking the time to check. Thomas. On Thursday, May 11, 2017 at 8:30:52 PM UTC+4, Simon Charette wrote: > > Hello Thomas, > > Probably caused by #28075 [0], fixed in 1.11.1. > > Cheers, > Simon > > [0] https://code.djangoproject.com/ticket/28075 > > Le jeudi 11 mai 2017 11:39:41 UTC-4, Alti a écrit : >> >> Hello, >> >> With localization and thousand separator active, my foreign keys ids are >> rendered with a thousand separator in django forms and give me an invalid >> field during validation. >> >> in settings.py: >> USE_L10N = True >> USE_THOUSAND_SEPARATOR = True >> >> example : >> Company something something >> with the french localization >> >> For now i just override the template >> django/forms/widgets/select_option.html with the safe filter : >> > "django/forms/widgets/attrs.html" %}>{{ widget.label }} >> >> I think it would be nicer to have the safe filter in the default template >> from django repository. >> >> Now i file it here to see if people consider it as a bug or if this >> behavior is considered as normal and if others get this problem as well, >> before filing a ticket on djangoproject.com. >> >> Regards, >> >> Thomas. >> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/23caa820-9f20-4738-a643-b5d3294eb3c2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.