Howdy,

I'm running into some odd behavior in the admin interface when my
model contains both a ForeignKey and a ManyToManyField relation.  I
suspect the issue may be caused by the fact that my ForeignKey and
ManyToManyField both reference the same model, which may very well be
an error on my part.

Here is my model:

class Cms_Consumer_Reports(models.Model):
    cms_consumer_reports_id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=765)
    description = models.TextField(blank=True)
    html = models.TextField(blank=True)
    html_title = models.TextField(blank=True)
    html_description = models.TextField(blank=True)
    html_keywords = models.TextField(blank=True)
    hidden = models.BooleanField()
    category_id = models.ForeignKey('ontology.Category',
db_column='category_id', verbose_name='Ontology Category')
    category = models.ManyToManyField('ontology.Category',
 
db_table='map_cms_consumer_reports_to_category',
                                      verbose_name='Associated
categories', help_text='Select all categories related to this report')
    right_column = models.TextField(blank=True)

When configured like this, the admin interface seems to ignore the
db_table parameter specified for category, the ManyToManyField, and
incorrectly performs a join against ontology.Category when populating
the values for category in the admin interface.

If, however, I comment out the ForeignKey relation as follows:

class Cms_Consumer_Reports(models.Model):
    cms_consumer_reports_id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=765)
    description = models.TextField(blank=True)
    html = models.TextField(blank=True)
    html_title = models.TextField(blank=True)
    html_description = models.TextField(blank=True)
    html_keywords = models.TextField(blank=True)
    hidden = models.BooleanField()
    # category_id = models.ForeignKey('ontology.Category',
db_column='category_id', verbose_name='Ontology Category')
    category = models.ManyToManyField('ontology.Category',
 
db_table='map_cms_consumer_reports_to_category',
                                      verbose_name='Associated
categories', help_text='Select all categories related to this report')
    right_column = models.TextField(blank=True)

The admin interface correctly populates the values of category using
the values from the specified join table,
map_cms_consumer_reports_to_category.

Any suggestions on how to work around this would be greatly
appreciated.

(Dan)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to