Re: Bug in Django 2.1 on ModelMultipleChoiceField
Hello If this is by design Django should raise an error indicating that ModelMultipleChoiceField does not allow an empty_label attribute The present error message in the __init__ of the super_class is not coherent and very difficult to understand for beginners. I would strongly suggest that it is filed as a bug to improve the code either by allowing the empty label or by raising the propoer error. Modifying the documentation does not seem sufficient from my point of view. Thanks for your suggestion for creating a specific class. Odile Lambert Le 13/03/2019 à 22:06, Matthew Pava a écrit : Looking at it, I would say that this is by design. You shouldn’t use an empty label on a multiple choice field. Perhaps this should be clarified in the docs. Saying that, if you really want an empty label on a multiple choice field, you could create your own class that initializes empty_label however you want it. From: 'Odile Lambert' via Django users [mailto:django-users@googlegroups.com] Sent: Wednesday, March 13, 2019 1:57 PM To: Django users Subject: Bug in Django 2.1 on ModelMultipleChoiceField Hello, I believe Bugs in Django are to be reported in this user list. Below is a report for a bug which does not seem to be already filed. In the documentation reference on the ModelMultipleChoiceField there is no restrictios mentioned on the empty_label attribute. Whenever you declare an attribute empy_label for a ModelMultipleChoiceField, it generates an error during the system_checks typeError " __init__() got multiple values for keyword argument 'empty_label To reproduce the bug : : class MyForm(forms.Form): field = forms.ModelMultipleChoiceField( queryset = Imodelclass.objects.all(),) empty_label=('')) Another user on stackoverflow encountered this same problem see here : https://stackoverflow.com/questions/52263426/django-empty-label-for-modelmultiplechoicefield-multiple-values-for-keyword-arg The cause of the error is the following : the code ( see fdjango/forms/models.py line 1266 sets the empty_label attribute to None while calling the super_class (ModelChoiceField): super().__init__(queryset, empty_label=None, **kwargs) while the super_class.__init__ sets the empy_label to "-". removing the empty_label= None in the call to the super_class solved the problem for me. best regards Odile Lambert -- 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/063841b4-5b58-4931-6ea3-29188ccc8171%40laposte.net. For more options, visit https://groups.google.com/d/optout. -- 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/c6be6380098a49b6bab737a85e1b5d5b%40iss2.ISS.LOCAL. For more options, visit https://groups.google.com/d/optout. -- 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/d1387fdf-7729-fc81-f311-0b4919fff6c0%40laposte.net. For more options, visit https://groups.google.com/d/optout.
Bug in Django 2.1 on ModelMultipleChoiceField
Hello, I believe Bugs in Django are to be reported in this user list. Below is a report for a bug which does not seem to be already filed. In the documentation reference on the ModelMultipleChoiceField there is no restrictios mentioned on the empty_label attribute. Whenever you declare an attribute empy_label for a ModelMultipleChoiceField, it generates an error during the system_checks typeError " __init__() got multiple values for keyword argument 'empty_label To reproduce the bug : : class MyForm(forms.Form): field = forms.ModelMultipleChoiceField( queryset = Imodelclass.objects.all(),) empty_label=('')) Another user on stackoverflow encountered this same problem see here : https://stackoverflow.com/questions/52263426/django-empty-label-for-modelmultiplechoicefield-multiple-values-for-keyword-arg The cause of the error is the following : the code ( see fdjango/forms/models.py line 1266 sets the empty_label attribute to None while calling the super_class (ModelChoiceField): super().__init__(queryset, empty_label=None, **kwargs) while the super_class.__init__ sets the empy_label to "-". removing the empty_label= None in the call to the super_class solved the problem for me. best regards Odile Lambert -- 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/063841b4-5b58-4931-6ea3-29188ccc8171%40laposte.net. For more options, visit https://groups.google.com/d/optout.
Key error for error messages in case the check on unique fails.
Hello I have a field in my model which has unique = True. If I specify an error message with a reference to the value of the field, Django crashes with Key error. Yet this works for other error_messages. How wan I solve this? Here is the code and the trace back https://dpaste.de/t5X8# Is this a bug in admin? I thank you in advance for your help. Piscvau -- 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/7fb7b0a0-7f36-7055-e751-16dbd2122fee%40laposte.net. For more options, visit https://groups.google.com/d/optout.
checkng for uniqueness of a field in django Admin
Hello In django admin, I have a model with a model fiel "tech_number" which must be unique across the table. If I do not check the uniqueness, it raises a Django integrity error. According to the documentation it sounds normal. I checked the uniqueness of the" tech_number" in the clean of the model form. but now it raises a validation error even in the change form. In fact it should ask if I needs to erase the existing one. What did I miss? Piscvau -- 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/8bf1dd1b-f42c-8d31-3331-9b112d7ca888%40laposte.net. For more options, visit https://groups.google.com/d/optout.
Re: Charfield variable length
Hello thank you very much for your answer. Your answer about the chafield max length is clear. I do not know how to clarify my use case because it is very special : the binary codes (there are 4) in the database will be used to set pushers on a knitting machine!...So what has a meaning for the user is really the position of the 0 and 1. Thus the idea of entering 0 and 1 characters. And the admin who creates the database must enter those fields !... He (she) also decides what is the max length of these binary codes, as this is a repeating factor. But physically the machine does not support more than 180 pushers, thus the admin may not enter more than 180 bits (0 and 1 characters) !... which is rather good news for him(she) Entering 180 0 and 1 characters is very unpractical but most of the time the repeating factor (max length of the binary codes) will be in the order of 10. There will be no search whatsoever in the database on this field which is just saved and will be used by a GUI to display information to the user and to do calculations. I hope this clarifies the need! I am now aiming to define a custom smallIntergerfield in the model, with a custom formfield and a textinput widget. As I am rather new to Django this is a fairly high challenge for which I will probably require more help. If you believe this is a crazy path, please let me know! Le 24/01/2019 à 01:52, Mike Dewhirst a écrit : On 24/01/2019 9:14 am, 'Odile Lambert' via Django users wrote: Hello I have problems with the Charfield max_length. In the source code, the possibility exists to have max_length = None but it does not pass Django check when models.py. contains a charfield = None I can understand that there is a need for such a max_length form the database point of view . When you run migrate it establishes the size of the Char field *in the database*. Therefore it can only be set once per migration. My need is the following: I have a set of fields whose content in the database is a binary code of maximum 180 bits. Most of the time it will be much shorter and there is in the form a field (max size) giving this maximum size. The user needs to input this field in the database as a Character string of 0 and 1. using hexadecimal fields would be very unpractical. Last but not least, I am using the admin to enter these data in the database. In a first shot, I used a Charfield and*I overwrote the field in the init to set the maximum length to the value chosen by the user. I also modifed the attributes of the widget. But at the end the HTML contains a texinput with the max length set in the model. * Is this an admin feature or did I miss something? A TextField is a varying length character field. Might be of interest. A binary field requires bytes not text. I think if I needed binary data entered by a user I would use a CharField with a reasonable max_length and in the model.save() method I would convert/interpret the data entered into precisely the binary format I needed and then programmatically store it into a "parallel" binary field. I would probably make it readonly in the Admin or just not display it. I'm not sure about using binary fields with a choice attribute but that might be another thing to research. You can certainly use choices in a CharField to totally restrict the data entered. . Any other suggestion on how to handle these fields would be welcomed. It might be easier to offer advice if your use-case was more clear. -- 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/23ff10f1-41d5-8da1-18a4-07d457be8756%40laposte.net . For more options, visit https://groups
Charfield variable length
Hello I have problems with the Charfield max_length. In the source code, the possibility exists to have max_length = None but it does not pass Django check when models.py. contains a charfield = None I can understand that there is a need for such a max_length form the database point of view . My need is the following: I have a set of fields whose content in the database is a binary code of maximum 180 bits. Most of the time it will be much shorter and there is in the form a field (max size) giving this maximum size. The user needs to input this field in the database as a Character string of 0 and 1. using hexadecimal fields would be very unpractical. Last but not least, I am using the admin to enter these data in the database. In a first shot, I used a Charfield and I overwrote the field in the init to set the maximum length to the value chosen by the user. I also modifed the attributes of the widget. But at the end the HTML contains a texinput with the max length set in the model. Is this an admin feature or did I miss something? . Any other suggestion on how to handle these fields would be welcomed. -- 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/23ff10f1-41d5-8da1-18a4-07d457be8756%40laposte.net. For more options, visit https://groups.google.com/d/optout.
auth.Group.permissions: (fields.E340) The field's intermediary table 'auth_group_permissions' clashes with the table name of 'mesrecettes.AuthGroupPermissions'
Hello I need to use an existing SQL database with Django. The database was under MSAccess. I generated a Dump of the database. I use SQL" source" command to generate my SQL database. Then I do Python manage.py inspectDB. I incorporate the proposed Django model in models.py. Then I do manage.py makemigrations. Then I do python manage.py migrate. And I get the following error message. File "/home/christian/djangorecettes/monvenv/lib/python3.6/site-packages/MySQLdb/connections.py", line 276, in query _mysql.connection.query(self, query) django.db.utils.OperationalError: (1050, "Table 'Categorie_de_recettes' already exists") After searching on the web it appears that it is an SQL error and several people mentionned going around it by changing from InnoDB to MyIsam engin. So I started the wohole process again modifying the dump with ENGINE= MYISAM. Python manage.py inspectDNB copy the model into models.py Python manage.py makemigrations. I get the following error message : auth.Group.permissions: (fields.E340) The field's intermediary table 'auth_group_permissions' clashes with the table name of 'mesrecettes.AuthGroupPermissions' I checked the model the following way: I used the generated models.py to generate an empty database. NO problem and the use of the admin form allows me to create elements in the database. Any suggestion would be much welcomed as I am getting desperate.>:o My next step could be to fill the empty database with SQL commands in batch but I would like to avoid it. Piscvau -- 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/587dfa02-d6f5-d6c2-bc99-2fd4e6ff396b%40yahoo.fr. For more options, visit https://groups.google.com/d/optout.