#28098: Error while doing migrations for a new model that is used in an form in 
the
admin.py
----------------------------------+--------------------------------------
     Reporter:  GHARIANI Mohamed  |                    Owner:  nobody
         Type:  Bug               |                   Status:  closed
    Component:  Migrations        |                  Version:  1.8
     Severity:  Normal            |               Resolution:  invalid
     Keywords:  migrations        |             Triage Stage:  Unreviewed
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+--------------------------------------
Changes (by Ramiro Morales):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Unfortunately your modelform makes no sense:
 {{{
 class AppForm(forms.ModelForm):
     name = ((elem.id, elem.name ) for elem in App.objects.all())
 }}}
 If you've followed advice from someone or read that somewhere stop using
 such help.

 And if that's code you created by yourself then please read the modelform
 documentation:
 https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/

 Django modelforms (like other components ike models, etc.) are defined in
 a **declarative** style.

 It makes no sense trying to define something in a declarative way by
 looping over a ORM queryset (DB query) like you are trying to do.

 When you see a model or  modelform definition think it's similar to an
 object or data structure definition which when using a static, compiled
 programming language (like C++, etc.) define its shape and behavior.

 Then when your Django app is running, these definitions are used together
 with your database and the information it contains. But this another
 latter, stage (thing runtime of a program as opposed to the compile time
 described above).

 This is why doesn't make sense to use a DB query when defining the
 modelform. You are trying to use data from the runtime stage at the
 modelform declaration stage.

--
Ticket URL: <https://code.djangoproject.com/ticket/28098#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/074.2e43d46a8b4e0aebd69b82f5e579a66e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to