Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I am new to Django, working on an existing website, leveraging the autoadmin to
- # quickly set up some data entries for the existing database. In the database there
- # is a reviews table. There are 2 image tables with a 1to1 relationship with review.
- # Unfortunately their id's do not correspond so it's modelled with a ForeignKey.
- # Each review has 1 of each image type. A thumbnail for a list of reviews, and
- # the other for the reviews detail page. I set the max_num_in_admin to 1 in the
- # ForeignKey which works for editing existing reviews, it only shows edit forms
- # for 1 image per Image table.
- # I wouldn't mind just leaving extra forms and leaving them blank, but the
- # database has not_null and Django tries to commit the empty forms to the database.
- # Setting max_num_in_admin to 1 works fine for changing existing reviews but
- # The problem is that it crashes on adding new ones. >>>>
- # KeyError at /admin/reviewsAdmin/review/add/ 'Field imagereviewbody.1.id not
- # found\n[FormField "id", FormField "short_name", FormField "description",
- # FormField "body", FormField "typeof", FormField "stars", FormField "active",
- # FormField "imagereviewbody.0.id", FormField "imagereviewbody.0.active",
- # FormField "imagereviewbody.0.relative_path_file", FormField
- # "imagereviewbody.0.relative_path", FormField "imagereviewbody.0.short_name"]'
- class Review(models.Model):
- id = models.IntegerField(primary_key=True)
- short_name = models.TextField()
- description = models.TextField()
- body = models.TextField()
- typeof = models.TextField()
- stars = models.FloatField()
- active = models.IntegerField()
- class Meta:
- db_table = u'review'
- class Admin:
- fields = (
- ('Review', {'fields': ('short_name','description', 'body', 'stars')}),
- ('Meta', {'fields': ('active', 'typeof')})
- )
- list_display = ('short_name', 'description', 'stars')
- search_fields = ['short_name']
- def __unicode__(self):
- return "%s" % self.short_name.strip()
- class ImageReviewListing(models.Model):
- id = models.IntegerField(primary_key=True)
- active = models.IntegerField()
- relative_path = models.TextField()
- short_name = models.TextField()
- description = models.TextField(editable=False)
- review = models.ForeignKey( Review)#, edit_inline=models.TABULAR)
- class Meta:
- db_table = u'image_review_listing'
- class ImageReviewBody(models.Model):
- id = models.IntegerField(primary_key=True)
- active = models.IntegerField()
- relative_path = models.ImageField(upload_to='images/')
- short_name = models.TextField()
- description = models.TextField(editable=False)
- review = models.ForeignKey(
- Review,
- edit_inline=models.TABULAR,
- max_num_in_admin=1
- )
- class Meta:
- db_table = u'image_review_body'
- class UserTable(models.Model):
- id = models.IntegerField(primary_key=True)
- username = models.CharField(unique=True, max_length=20)
- password = models.CharField(max_length=20)
- email = models.CharField(max_length=255)
- class Meta:
- db_table = u'user_table'
- class Profile(models.Model):
- id = models.IntegerField(primary_key=True)
- short_name = models.TextField()
- description = models.TextField()
- body = models.TextField()
- website = models.TextField()
- email = models.CharField(max_length=255)
- active = models.IntegerField()
- class Meta:
- db_table = u'profile'
- def __unicode__(self):
- return self.short_name
- class ProfileAlias(models.Model):
- id = models.IntegerField(primary_key=True)
- short_name = models.TextField()
- description = models.TextField()
- body = models.TextField()
- website = models.TextField()
- email = models.CharField(max_length=255)
- active = models.IntegerField()
- user = models.ForeignKey(UserTable)
- class Meta:
- db_table = u'profile_alias'
- def __unicode__(self):
- return self.short_name
- class ChangeReview(models.Model):
- id = models.IntegerField(primary_key=True)
- profile_alias = models.ForeignKey(ProfileAlias)
- profile = models.ForeignKey(Profile)
- when_changed = models.DateTimeField()
- review = models.ForeignKey(Review)#, edit_inline=models.TABULAR)
- class Meta:
- db_table = u'change_review'
- class MetaReview(models.Model):
- id = models.IntegerField(primary_key=True)
- body = models.TextField()
- name = models.TextField()
- review = models.ForeignKey(Review)
- class Meta:
- db_table = u'meta_review'
Add Comment
Please, Sign In to add comment