UUIDField from django-extensions is not available in Class Based Views

37 views
Skip to first unread message

Timothy W. Cook

unread,
Jan 20, 2014, 4:03:18 PM1/20/14
to django...@googlegroups.com


I have a web application where I use a couple of UUIDFields. In the Admin UI, in function based views and other Python code, these fields work as expected. However, when trying to list them in the 'fields' in a CBV, I get the error:

FieldError(message) django.core.exceptions.FieldError: Unknown field(s) (ct_id) 

The subject field here is ct_id. But another one does the same.

From models.py:

ct_id = UUIDField(_("UUID"), version=4, help_text=_('A unique identifier for this PCT.'))

As mentioned above, they work in Admin lists:

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

In function based views to create JSON for DynaTree:

pct_json['tooltip'] = 'ct-'+pct.ct_id + " : " +pct.description

But in a CBV, this raises the error:

fields =['published','prj_name','data_name',ct_id,]

Any ideas on how to make this work? I only want to render them for display, not for editing.

Thanks,

Tim

PS. This question is also on StackOverflow at:   http://goo.gl/mA7I6V 


--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc           +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook

Timothy W. Cook

unread,
Jan 20, 2014, 4:55:57 PM1/20/14
to django...@googlegroups.com
BTW:

In the actual code the ct_id field is quaoted correctly.  It was just an error in my post here. 
fields =['published','prj_name','data_name','ct_id',]

Timothy W. Cook

unread,
Jan 21, 2014, 5:15:13 AM1/21/14
to django...@googlegroups.com
SOLVED:  (sort of)

I am not sure if this is the only or best way to solve the problem. But, since I needed to use get_context_data() in the view anyway. I am now doing this to get ct_id into the view template:

def get_context_data(self,**kwargs):
    context = super(DvStringUpdateView, self).get_context_data(**kwargs)
    semlinks = []
    obj = get_object_or_404(DvString,pk=context['object'].id)
    if obj.resource_uri:
        urilist = obj.resource_uri.splitlines()
        attrlist = obj.sem_attr.splitlines()        
        for n in range(0,len(urilist)):
            semlinks.append(attrlist[n] + ' = ' + unquote(urilist[n]))

    context['semlinks'] = semlinks
    context['ct_id'] = obj.ct_id
    return context



Is there a bug in the way the UUIDField is defined causing it to not be available in CBVs? This is at least a workaround.


Cheers,
Tim


Reply all
Reply to author
Forward
0 new messages