Guest User

Untitled

a guest
Apr 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. # I am new to Django, working on an existing website, leveraging the autoadmin to
  2. # quickly set up some data entries for the existing database. In the database there
  3. # is a reviews table. There are 2 image tables with a 1to1 relationship with review.
  4. # Unfortunately their id's do not correspond so it's modelled with a ForeignKey.
  5. # Each review has 1 of each image type. A thumbnail for a list of reviews, and
  6. # the other for the reviews detail page. I set the max_num_in_admin to 1 in the
  7. # ForeignKey which works for editing existing reviews, it only shows edit forms
  8. # for 1 image per Image table.
  9.  
  10. # I wouldn't mind just leaving extra forms and leaving them blank, but the
  11. # database has not_null and Django tries to commit the empty forms to the database.
  12.  
  13. # Setting max_num_in_admin to 1 works fine for changing existing reviews but
  14. # The problem is that it crashes on adding new ones. >>>>
  15.  
  16. # KeyError at /admin/reviewsAdmin/review/add/ 'Field imagereviewbody.1.id not
  17. # found\n[FormField "id", FormField "short_name", FormField "description",
  18. # FormField "body", FormField "typeof", FormField "stars", FormField "active",
  19. # FormField "imagereviewbody.0.id", FormField "imagereviewbody.0.active",
  20. # FormField "imagereviewbody.0.relative_path_file", FormField
  21. # "imagereviewbody.0.relative_path", FormField "imagereviewbody.0.short_name"]'
  22.  
  23. class Review(models.Model):
  24. id = models.IntegerField(primary_key=True)
  25. short_name = models.TextField()
  26. description = models.TextField()
  27. body = models.TextField()
  28. typeof = models.TextField()
  29. stars = models.FloatField()
  30. active = models.IntegerField()
  31.  
  32. class Meta:
  33. db_table = u'review'
  34.  
  35. class Admin:
  36.  
  37. fields = (
  38. ('Review', {'fields': ('short_name','description', 'body', 'stars')}),
  39. ('Meta', {'fields': ('active', 'typeof')})
  40. )
  41.  
  42. list_display = ('short_name', 'description', 'stars')
  43.  
  44. search_fields = ['short_name']
  45.  
  46. def __unicode__(self):
  47. return "%s" % self.short_name.strip()
  48.  
  49. class ImageReviewListing(models.Model):
  50. id = models.IntegerField(primary_key=True)
  51. active = models.IntegerField()
  52. relative_path = models.TextField()
  53. short_name = models.TextField()
  54. description = models.TextField(editable=False)
  55. review = models.ForeignKey( Review)#, edit_inline=models.TABULAR)
  56. class Meta:
  57. db_table = u'image_review_listing'
  58.  
  59. class ImageReviewBody(models.Model):
  60. id = models.IntegerField(primary_key=True)
  61. active = models.IntegerField()
  62. relative_path = models.ImageField(upload_to='images/')
  63. short_name = models.TextField()
  64. description = models.TextField(editable=False)
  65. review = models.ForeignKey(
  66. Review,
  67. edit_inline=models.TABULAR,
  68. max_num_in_admin=1
  69. )
  70. class Meta:
  71. db_table = u'image_review_body'
  72.  
  73. class UserTable(models.Model):
  74. id = models.IntegerField(primary_key=True)
  75. username = models.CharField(unique=True, max_length=20)
  76. password = models.CharField(max_length=20)
  77. email = models.CharField(max_length=255)
  78. class Meta:
  79. db_table = u'user_table'
  80.  
  81. class Profile(models.Model):
  82. id = models.IntegerField(primary_key=True)
  83. short_name = models.TextField()
  84. description = models.TextField()
  85. body = models.TextField()
  86. website = models.TextField()
  87. email = models.CharField(max_length=255)
  88. active = models.IntegerField()
  89. class Meta:
  90. db_table = u'profile'
  91.  
  92. def __unicode__(self):
  93. return self.short_name
  94.  
  95. class ProfileAlias(models.Model):
  96. id = models.IntegerField(primary_key=True)
  97. short_name = models.TextField()
  98. description = models.TextField()
  99. body = models.TextField()
  100. website = models.TextField()
  101. email = models.CharField(max_length=255)
  102. active = models.IntegerField()
  103. user = models.ForeignKey(UserTable)
  104. class Meta:
  105. db_table = u'profile_alias'
  106. def __unicode__(self):
  107. return self.short_name
  108.  
  109. class ChangeReview(models.Model):
  110. id = models.IntegerField(primary_key=True)
  111. profile_alias = models.ForeignKey(ProfileAlias)
  112. profile = models.ForeignKey(Profile)
  113. when_changed = models.DateTimeField()
  114. review = models.ForeignKey(Review)#, edit_inline=models.TABULAR)
  115. class Meta:
  116. db_table = u'change_review'
  117.  
  118. class MetaReview(models.Model):
  119. id = models.IntegerField(primary_key=True)
  120. body = models.TextField()
  121. name = models.TextField()
  122. review = models.ForeignKey(Review)
  123. class Meta:
  124. db_table = u'meta_review'
Add Comment
Please, Sign In to add comment