Django Admin UI Bug - 1.7.3

32 views
Skip to first unread message

Timothy W. Cook

unread,
Jan 16, 2015, 2:56:47 PM1/16/15
to django...@googlegroups.com
Is this a bug or did I miss something in the release notes?  

​Moving from 1.6.4 to 1.7.3  the listing in the Admin UI is not resolving a related field now.  There are not any model changes involved. 

Attached are two screen shots named for the versions.

I haven't changed the admin code either.  For the screen shots the admin code is:

class DvBooleanAdmin(admin.ModelAdmin):
    list_filter = ['prj_name__rm_version__version_id','prj_name',]
    search_fields = ['data_name','ct_id']
    ordering = ['prj_name','data_name']
    actions = [make_published, unpublish, copy_dt, republish]
    readonly_fields = ['published','schema_code','r_code','xqr_code','xqw_code',]
    def get_form(self, request, obj=None, **kwargs):
        try:
            if obj.published:
                self.readonly_fields = ['prj_name','published','lang','schema_code','data_name','valid_trues','valid_falses','description','sem_attr','resource_uri','asserts','xqr_code','xqw_code',]
        except (AttributeError, TypeError) as e:
            self.readonly_fields = ['published','schema_code','r_code','xqr_code','xqw_code',]
        return super(DvBooleanAdmin, self).get_form(request, obj, **kwargs)

    fieldsets = (
        (None, {'classes':('wide',),
                       'fields':('published','prj_name','data_name','lang','valid_trues','valid_falses')}),
        ("Additional Information ", {'classes':('wide',),
                       'fields':('description','sem_attr','resource_uri','asserts',)}),
        ("PCT Code (read-only)", {'classes':('collapse',),
                           'fields':('schema_code','r_code','xqr_code','xqw_code',)}),

    )
    list_display = ('data_name','prj_name','published',)
admin.site.register(DvBoolean, DvBooleanAdmin)

​In the model for the displayed admin:
​    prj_name = models.ForeignKey(Project, verbose_name=_("Project Name"), to_field="prj_name", help_text=_('Choose the name of your Project.'))

​and the related field in Project is:
    prj_name = models.CharField(_("project name"), max_length=110, unique=True, db_index=True, help_text=_('Enter the name of your project.'))

...

    def __unicode__(self):
            return self.prj_name


​Any ideas?​

Should I file a bug report? 

​Thanks,
Tim



 

============================================
Timothy Cook
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

Django-1.6.4.png
Django-1.7.3.png

Timothy W. Cook

unread,
Jan 16, 2015, 3:14:55 PM1/16/15
to django...@googlegroups.com
I should also mention that I have some AJAX calls for the same information and they still work fine.  So I am quite certain it is in the Admin templates or the Admin properties definitions. 
--

Collin Anderson

unread,
Jan 17, 2015, 8:49:06 AM1/17/15
to django...@googlegroups.com
Hi,

Did you also switch to Python 3?
It doesn't seem to be using your __unicode__ method at all.
If you query one of these Projects in manage.py shell, do they show the project name?
Are you sure that the __unicode__ method is actually attached to your model?

Also, FYI, to_field="prj_name" means you can't easily change the name of the project.

Collin

Timothy W. Cook

unread,
Jan 18, 2015, 12:31:06 PM1/18/15
to django...@googlegroups.com
On Sat, Jan 17, 2015 at 11:49 AM, Collin Anderson <cmawe...@gmail.com> wrote:
Hi,

Did you also switch to Python 3?

​Yes. 

Well, I didn't switch. I have been using Python 3 for quite some time.  Even before it was officially supported. 
 
It doesn't seem to be using your __unicode__ method at all.
If you query one of these Projects in manage.py shell, do they show the project name?

​As I said before, my views that use AJAX to return data from queries still work just as before.  But yes, in the manage.py shell I can import the models and print the names.

>>> from ccdgen.models import DvBoolean,DvAny, Common, Project
>>> pcts = DvBoolean.objects.all()
>>> for p in pcts:
...   print(p.prj_name.prj_name)
 
caBIG
caBIG
caBIG
caBIG
caBIG
caBIG
caBIG

... 



 
Are you sure that the __unicode__ method is actually attached to your model?


I am not exactly sure what you mean by that question; attached?    ​Here is the code: ​

class Project(models.Model):
    """
    Every item created in CCDGEN must be assigned to a Project when created. All items (except CCD) may be
    reused in multiple CCDs. However, this does not change the original Project.
    The Allowed Groups field contains each of the User Groups allowed to see each item with this Project name.
    The User Group, Open, is assigned to every user. So if you assign the Open group as one of the allowed groups,
    all CCDGEN users will see this item.
    """
    pgroup = models.ForeignKey(Group, verbose_name='Primary Group', related_name='primarygroup', null=True)
    prj_name = models.CharField(_("project name"), max_length=110, unique=True, db_index=True, help_text=_('Enter the name of your project.'))
    description = models.TextField(_("project description"), blank=True, help_text=_('Enter a description or explaination of an acronym of the project.'))
    rm_version = models.ForeignKey(RMversion, verbose_name=_('rm version'), related_name='%(class)s_related', help_text=_('Choose the version of the MLHIM Reference Model you are using.'))
    allowed_groups = models.ManyToManyField(Group, verbose_name=_('allowed groups'), related_name='%(class)s_related', help_text=_('Choose the groups that are allowed to work in this project.'))

    def __unicode__(self):
            return self.prj_name


    class Meta:
        verbose_name = _("Project")
        verbose_name_plural = _("Projects")
        ordering = ['prj_name']


 
Also, FYI, to_field="prj_name" means you can't easily change the name of the project.


​Yes, Once created the name cannot be changed, and once an item is assigned to a project the attached items are immutable. 

Thanks,
Tim


 

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d9cf8bcf-5311-46bb-b902-83042d27a94d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Collin Anderson

unread,
Jan 18, 2015, 2:35:12 PM1/18/15
to django...@googlegroups.com
Hi,

Rename your __unicode__ to __str__. Python 3 doesn't know what "__unicode__" is. :)

You say this works fine:
>>> from ccdgen.models import DvBoolean,DvAny, Common, Project
>>> pcts = DvBoolean.objects.all()
>>> for p in pcts:
...   print(p.prj_name.prj_name)

But django is expecting this also to work:
>>> pcts = DvBoolean.objects.all()
>>> for p in pcts:
...   print(p.prj_name)

Collin

Timothy W. Cook

unread,
Jan 18, 2015, 2:49:49 PM1/18/15
to django...@googlegroups.com
On Sun, Jan 18, 2015 at 5:35 PM, Collin Anderson <collinm...@gmail.com> wrote:
Hi,

Rename your __unicode__ to __str__. Python 3 doesn't know what "__unicode__" is. :)


​Yep, that did it.​  Interesting that it was working up until now and that my AJAX calls worked either way.  <shrug> 

 
You say this works fine:
>>>
​​
from ccdgen.models import DvBoolean,DvAny, Common, Project
>>> pcts = DvBoolean.objects.all()
>>> for p in pcts:
...   print(p.prj_name.prj_name)

But django is expecting this also to work:
>>> pcts = DvBoolean.objects.all()
>>> for p in pcts:
...   print(p.prj_name)

​It does now.  It did not before the change above.​


​Thanks,
Tim


Reply all
Reply to author
Forward
0 new messages