django sets Meta.fields to None

2009-02-03 Thread JonUK

I have the following class:

class QuoteForm( ModelForm ):

class Meta:
fields = [ 'user', 'photo', 'created', 'usage', 'complete', ]
model = Quote

def __init__(self, *args, **kwargs ):
import pdb; pdb.set_trace()
super( QuoteForm, self ).__init__( *args, **kwargs )
import pdb; pdb.set_trace()
self.fields.keyOrder = self.Meta.fields

when I debug, I get the following results:

-> super( QuoteForm, self ).__init__( *args, **kwargs )
(Pdb) dir (self.Meta)
['__doc__', '__module__', 'exclude', 'fields', 'model']
(Pdb) p self.Meta.exclude, self.Meta.fields, self.Meta.model
([], None, )
(Pdb) p self.fields
*** AttributeError: AttributeError("'QuoteForm' object has no
attribute 'fields'",)
(Pdb) c
> c:\development\repositories\jhp\jhp\website\forms.py(58)__init__()
-> self.fields.keyOrder = self.Meta.fields
(Pdb) p self.Meta.exclude, self.Meta.fields, self.Meta.model
([], None, )
(Pdb) p self.fields
{'user': ,
'photo': , 'usage': , 'created': , 'complete':
}
(Pdb)

django has set Meta.fields to None, ensuring that:
a) fields are not rendered in the correct order, and
b) a 'NoneType' object is not iterable exception occurs on saving

Can anyone explain this problem?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Re: Admin screen counts correctly but returns no records

2009-01-29 Thread JonUK

Thanks Daniel, I'll take your advice.

I'm surprised (i.e. don't understand why) this approach is problematic
though.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Admin screen counts correctly but returns no records

2009-01-29 Thread JonUK

I'm creating a new admin UI for User, separate to the standard admin
User interface - I have the following setup:

class WebsiteUser( User ):
class Meta:
db_table = 'auth_user'

class WebsiteUserAdmin( admin.ModelAdmin ):
list_display = ( 'username', )

admin.site.register( WebsiteUser, WebsiteUserAdmin )

When I view this, the admin list page correctly summarises "1 website
user", however it has no rows.

Any ideas?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Re: Form validated before submitted

2009-01-27 Thread JonUK

Solved - problem was caused by these lines

def __init__(self, *args, **kwargs ):
   super( ContactForm, self ).__init__( args, kwargs )

changing to explicit parameter names fixed it.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Form validated before submitted

2009-01-27 Thread JonUK

I have a ModelForm and a view, but the form's validation messages are
always rendered on first viewing - any idea why?

# ModelForm
class ContactForm( ModelForm ):
first_name = CharField( 'Firstname' )
last_name = CharField( 'Lastname' )
company = CharField( 'Company' )
tel = CharField( 'Telephone' )
email = EmailField( 'Email' )
message = CharField( 'Message', widget=Textarea )

class Meta:
model = Contact
fields = ( 'first_name', 'last_name', 'company', 'tel',
'email', 'message', )

def __init__(self, *args, **kwargs ):
super( ContactForm, self ).__init__( args, kwargs )
self.fields.keyOrder = self.Meta.fields

# View
def contact( request ):
if request.method == 'POST':
contact = ContactForm( request.POST, auto_id='contact_%s' )
if contact.is_valid():
contact.user = request.user
contact.save()
contact = None
else:
contact = ContactForm( auto_id='contact_%s' )
return render_to_response( 'contact.html',
{ 'contact' : contact, },
context_instance = RequestContext( request ) )
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Re: in what namespace do widgets reside?

2009-01-27 Thread JonUK

great - thanks!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



in what namespace do widgets reside?

2009-01-27 Thread JonUK

Apologies for the daft question, but after 10 mins of trawling through
the official docs and various random google articles, I cannot find
thyis info.

Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Re: How to obtain an intermediate ManyToMany object?

2009-01-16 Thread JonUK

Thank You! That was the correct syntax :)

For anyone else with the same problem, you can also utilise
"related_name" to provide syntactically pleasing access to your
objects (have changed class name LightboxPhotograph to Item), such as:

lightbox.photographs.all() - to retrieve Photograph objects
lightbox.items.all() - to retrieve Item objects
photgraphy.items.all()
photgraphy.lightboxes.all()

class Photograph(ImageModel):
pass

class Lightbox(models.Model):
photographs = models.ManyToManyField('Photograph',
related_name='lightboxes',
through = 'Item',
symmetrical=False,
verbose_name=_('photographs'),
null=True, blank=True)

class Item(models.Model):
lightbox = models.ForeignKey( Lightbox, related_name='items' )
photograph = models.ForeignKey( Photograph, related_name='items' )
order = models.IntegerField( unique=False )

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Re: How to obtain an intermediate ManyToMany object?

2009-01-16 Thread JonUK

Thank You! That was the correct syntax :)

For anyone else with the same problem, you can also utilise
"related_name" to provide syntactically pleasing access to your
objects, such as:

lightbox.photographs.all() - to retrieve Photograph objects
lightbox.items.all() - to retrieve Item objects
photgraphy.items.all()
photgraphy.lightboxes.all()

class Photograph(ImageModel):
pass

class Lightbox(models.Model):
photographs = models.ManyToManyField('Photograph',
related_name='lightboxes',
through = 'Item',
symmetrical=False,
verbose_name=_('photographs'),
null=True, blank=True)

class Item(models.Model):
lightbox = models.ForeignKey( Lightbox, related_name='items' )
photograph = models.ForeignKey( Photograph, related_name='items' )
order = models.IntegerField( unique=False )

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Re: How to obtain an intermediate ManyToMany object?

2009-01-15 Thread JonUK

lightbox.lightboxphotograph_set yields:

TypeError: "'RelatedManager' object is not iterable"

:(
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



Re: How to obtain an intermediate ManyToMany object?

2009-01-15 Thread JonUK

Thanks, but that gives me:

AttributeError: "'Lightbox' object has no attribute 'lightboxes'"

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



How to obtain an intermediate ManyToMany object?

2009-01-15 Thread JonUK

I have this model (bits omitted for brevity):

class Photograph(ImageModel):
title = models.CharField(_('title'), max_length=100, unique=True )

class Lightbox(models.Model):
photographs = models.ManyToManyField('Photograph',
related_name='lightboxes',
through =
'LightboxPhotograph',
symmetrical=False,
verbose_name=_('photographs'),
null=True, blank=True)

class LightboxPhotograph(models.Model):
lightbox = models.ForeignKey( Lightbox )
photograph = models.ForeignKey( Photograph )
order = models.IntegerField( unique=False )

how do iterate the LightboxPhotograph objects for a given instance of
LightBox?

e.g.

for x in lightbox.iterable_LightboxPhotograph_objects

such that: type(x) == LightboxPhotograph

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



django discarding MySQL results for "in" operator

2009-01-05 Thread JonUK

Apologies as this is a repost, but I'm completely stuck!

I'm using django 1.0.2 and the tagging app to retrieve a tag via a
database "in" query, and something is causing the query results to be
discarded.

In particular, this line of code from tagging.utils.get_tag_list()
executes:

return Tag.objects.filter(name__in=[force_unicode(tag)
  for tag in tags])

and at this point:
(Pdb) p tags
[u'sea']

The thread of execution can be traced into the method
django.db.models.sql.query.execute_sql(self, result_type=MULTI), and
to this line of code:

cursor.execute(sql, params)

and over here:
>
c:\python26\lib\site-packages\django\db\models\sql\query.py(1735)
execute_sql()

-> cursor.execute(sql, params)
(Pdb) p sql
'SELECT "tagging_tag"."id", "tagging_tag"."name" FROM "tagging_tag"
WHERE "tagging_tag"."name" IN (%s) ORDER BY "tagging_tag"."name" ASC'
(Pdb) p params
(u'sea',)
(Pdb)

If I audit what's submitted to MySQL via MySQL logging, it reports:
SELECT `tagging_tag`.`id`, `tagging_tag`.`name` FROM `tagging_tag`
WHERE `tagging_tag`.`name` IN ('sea') ORDER BY `tagging_tag`.`name`
ASC

which looks correct - however django returns an empty list.

If I execute the query interactively in MySQL, I get the expected
(correct) result:

++--+
| id | name |
++--+
| 28 | Sea  |
++--+
1 row in set (0.00 sec)

I suspect this is a configuration problem but have no idea where to
look - can anyone help?

Thanks

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---



django ignoring MySQL case insensitivity for "in" operator

2009-01-04 Thread JonUK

I'm using django 1.0.2 and the tagging app to retrieve a tag via a
database "in" query, and something is causing the "in" operator's
native nehaviour to be ignored.

In particular, this line of code from tagging.utils.get_tag_list()
executes:

return Tag.objects.filter(name__in=[force_unicode(tag)
\
for tag in tags])

and at this point:
(Pdb) p tags
[u'sea']

The execution thread can be traced into the method
django.db.models.sql.query.execute_sql(self, result_type=MULTI), and
to this line of code:

cursor.execute(sql, params)

and over here:
> c:\python26\lib\site-packages\django\db\models\sql\query.py(1735)execute_sql()
-> cursor.execute(sql, params)
(Pdb) p sql
'SELECT "tagging_tag"."id", "tagging_tag"."name" FROM "tagging_tag"
WHERE "tagging_tag"."name" IN (%s) ORDER BY "tagging_tag"."name" ASC'
(Pdb) p params
(u'sea',)
(Pdb)

If I audit the query via MySQL logging, it reports:
SELECT `tagging_tag`.`id`, `tagging_tag`.`name` FROM `tagging_tag`
WHERE `tagging_tag`.`name` IN ('sea') ORDER BY `tagging_tag`.`name`
ASC

which looks correct - however django returns an empty list.

If I execute the query interactively in MySQL, I get the expected
result:

++--+
| id | name |
++--+
| 28 | Sea  |
++--+
1 row in set (0.00 sec)

I suspect this is a configuration problem but have no idea where to
look - can anyone help?

Thanks

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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
-~--~~~~--~~--~--~---