Permalink
Browse files

Fixed #122 -- BIG, BACKWARDS-INCOMPATIBLE CHANGE. Changed model synta…

…x to use fieldname=FieldClass() syntax. See ModelSyntaxChangeInstructions for important information on how to change your models

git-svn-id: http://code.djangoproject.com/svn/django/trunk@549 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent aec0a73 commit 25264c86048d442a4885dfebae94510e2fa0c1e4 @adrianholovaty adrianholovaty committed Aug 25, 2005
Showing with 957 additions and 721 deletions.
  1. +101 −108 django/contrib/comments/models/comments.py
  2. +2 −2 django/contrib/comments/templatetags/comments.py
  3. +3 −3 django/contrib/comments/views/comments.py
  4. +4 −4 django/contrib/comments/views/userflags.py
  5. +10 −8 django/core/management.py
  6. +172 −111 django/core/meta/__init__.py
  7. +57 −41 django/core/meta/fields.py
  8. +64 −72 django/models/auth.py
  9. +62 −70 django/models/core.py
  10. +6 −6 django/templatetags/log.py
  11. +10 −10 django/views/admin/main.py
  12. +2 −2 django/views/defaults.py
  13. +18 −31 docs/db-api.txt
  14. +2 −7 docs/faq.txt
  15. +8 −8 docs/forms.txt
  16. +37 −67 docs/model-api.txt
  17. +13 −18 docs/overview.txt
  18. +22 −24 docs/tutorial01.txt
  19. +5 −7 docs/tutorial02.txt
  20. +2 −1 tests/testapp/models/__init__.py
  21. +2 −4 tests/testapp/models/basic.py
  22. +2 −4 tests/testapp/models/custom_methods.py
  23. +5 −6 tests/testapp/models/custom_pk.py
  24. +4 −5 tests/testapp/models/get_latest.py
  25. +4 −5 tests/testapp/models/lookup.py
  26. +12 −18 tests/testapp/models/m2m_intermediary.py
  27. +7 −11 tests/testapp/models/m2o_recursive.py
  28. +7 −15 tests/testapp/models/m2o_recursive2.py
  29. +3 −7 tests/testapp/models/many_to_many.py
  30. +39 −15 tests/testapp/models/many_to_one.py
  31. +77 −0 tests/testapp/models/many_to_one_null.py
  32. +14 −13 tests/testapp/models/one_to_one.py
  33. +8 −9 tests/testapp/models/ordering.py
  34. +3 −5 tests/testapp/models/repr.py
  35. +2 −4 tests/testapp/models/save_delete_hooks.py
  36. +168 −0 tests/testapp/models/subclassing.py
@@ -2,59 +2,56 @@
from django.models import auth, core
class Comment(meta.Model):
- db_table = 'comments'
- fields = (
- meta.ForeignKey(auth.User, raw_id_admin=True),
- meta.ForeignKey(core.ContentType, name='content_type_id', rel_name='content_type'),
- meta.IntegerField('object_id', 'object ID'),
- meta.CharField('headline', 'headline', maxlength=255, blank=True),
- meta.TextField('comment', 'comment', maxlength=3000),
- meta.PositiveSmallIntegerField('rating1', 'rating #1', blank=True, null=True),
- meta.PositiveSmallIntegerField('rating2', 'rating #2', blank=True, null=True),
- meta.PositiveSmallIntegerField('rating3', 'rating #3', blank=True, null=True),
- meta.PositiveSmallIntegerField('rating4', 'rating #4', blank=True, null=True),
- meta.PositiveSmallIntegerField('rating5', 'rating #5', blank=True, null=True),
- meta.PositiveSmallIntegerField('rating6', 'rating #6', blank=True, null=True),
- meta.PositiveSmallIntegerField('rating7', 'rating #7', blank=True, null=True),
- meta.PositiveSmallIntegerField('rating8', 'rating #8', blank=True, null=True),
- # This field designates whether to use this row's ratings in
- # aggregate functions (summaries). We need this because people are
- # allowed to post multiple review on the same thing, but the system
- # will only use the latest one (with valid_rating=True) in tallying
- # the reviews.
- meta.BooleanField('valid_rating', 'is valid rating'),
- meta.DateTimeField('submit_date', 'date/time submitted', auto_now_add=True),
- meta.BooleanField('is_public', 'is public'),
- meta.IPAddressField('ip_address', 'IP address', blank=True, null=True),
- meta.BooleanField('is_removed', 'is removed',
- help_text='Check this box if the comment is inappropriate. A "This comment has been removed" message will be displayed instead.'),
- meta.ForeignKey(core.Site),
- )
- module_constants = {
- # min. and max. allowed dimensions for photo resizing (in pixels)
- 'MIN_PHOTO_DIMENSION': 5,
- 'MAX_PHOTO_DIMENSION': 1000,
-
- # option codes for comment-form hidden fields
- 'PHOTOS_REQUIRED': 'pr',
- 'PHOTOS_OPTIONAL': 'pa',
- 'RATINGS_REQUIRED': 'rr',
- 'RATINGS_OPTIONAL': 'ra',
- 'IS_PUBLIC': 'ip',
- }
- ordering = ('-submit_date',)
- admin = meta.Admin(
- fields = (
- (None, {'fields': ('content_type_id', 'object_id', 'site_id')}),
- ('Content', {'fields': ('user_id', 'headline', 'comment')}),
- ('Ratings', {'fields': ('rating1', 'rating2', 'rating3', 'rating4', 'rating5', 'rating6', 'rating7', 'rating8', 'valid_rating')}),
- ('Meta', {'fields': ('is_public', 'is_removed', 'ip_address')}),
- ),
- list_display = ('user_id', 'submit_date', 'content_type_id', 'get_content_object'),
- list_filter = ('submit_date',),
- date_hierarchy = 'submit_date',
- search_fields = ('comment', 'user__username'),
- )
+ user = meta.ForeignKey(auth.User, raw_id_admin=True)
+ content_type = meta.ForeignKey(core.ContentType)
+ object_id = meta.IntegerField('object ID')
+ headline = meta.CharField(maxlength=255, blank=True)
+ comment = meta.TextField(maxlength=3000)
+ rating1 = meta.PositiveSmallIntegerField('rating #1', blank=True, null=True)
+ rating2 = meta.PositiveSmallIntegerField('rating #2', blank=True, null=True)
+ rating3 = meta.PositiveSmallIntegerField('rating #3', blank=True, null=True)
+ rating4 = meta.PositiveSmallIntegerField('rating #4', blank=True, null=True)
+ rating5 = meta.PositiveSmallIntegerField('rating #5', blank=True, null=True)
+ rating6 = meta.PositiveSmallIntegerField('rating #6', blank=True, null=True)
+ rating7 = meta.PositiveSmallIntegerField('rating #7', blank=True, null=True)
+ rating8 = meta.PositiveSmallIntegerField('rating #8', blank=True, null=True)
+ # This field designates whether to use this row's ratings in aggregate
+ # functions (summaries). We need this because people are allowed to post
+ # multiple reviews on the same thing, but the system will only use the
+ # latest one (with valid_rating=True) in tallying the reviews.
+ valid_rating = meta.BooleanField('is valid rating')
+ submit_date = meta.DateTimeField('date/time submitted', auto_now_add=True)
+ is_public = meta.BooleanField()
+ ip_address = meta.IPAddressField('IP address', blank=True, null=True)
+ is_removed = meta.BooleanField(help_text='Check this box if the comment is inappropriate. A "This comment has been removed" message will be displayed instead.')
+ site = meta.ForeignKey(core.Site)
+ class META:
+ db_table = 'comments'
+ module_constants = {
+ # min. and max. allowed dimensions for photo resizing (in pixels)
+ 'MIN_PHOTO_DIMENSION': 5,
+ 'MAX_PHOTO_DIMENSION': 1000,
+
+ # option codes for comment-form hidden fields
+ 'PHOTOS_REQUIRED': 'pr',
+ 'PHOTOS_OPTIONAL': 'pa',
+ 'RATINGS_REQUIRED': 'rr',
+ 'RATINGS_OPTIONAL': 'ra',
+ 'IS_PUBLIC': 'ip',
+ }
+ ordering = ('-submit_date',)
+ admin = meta.Admin(
+ fields = (
+ (None, {'fields': ('content_type', 'object_id', 'site')}),
+ ('Content', {'fields': ('user', 'headline', 'comment')}),
+ ('Ratings', {'fields': ('rating1', 'rating2', 'rating3', 'rating4', 'rating5', 'rating6', 'rating7', 'rating8', 'valid_rating')}),
+ ('Meta', {'fields': ('is_public', 'is_removed', 'ip_address')}),
+ ),
+ list_display = ('user', 'submit_date', 'content_type', 'get_content_object'),
+ list_filter = ('submit_date',),
+ date_hierarchy = 'submit_date',
+ search_fields = ('comment', 'user__username'),
+ )
def __repr__(self):
return "%s: %s..." % (self.get_user().username, self.comment[:100])
@@ -156,32 +153,31 @@ def _module_user_is_moderator(user):
return False
class FreeComment(meta.Model):
- "A FreeComment is a comment by a non-registered user"
- db_table = 'comments_free'
- fields = (
- meta.ForeignKey(core.ContentType, name='content_type_id', rel_name='content_type'),
- meta.IntegerField('object_id', 'object ID'),
- meta.TextField('comment', 'comment', maxlength=3000),
- meta.CharField('person_name', "person's name", maxlength=50),
- meta.DateTimeField('submit_date', 'date/time submitted', auto_now_add=True),
- meta.BooleanField('is_public', 'is public'),
- meta.IPAddressField('ip_address', 'IP address'),
- # TODO: Change this to is_removed, like Comment
- meta.BooleanField('approved', 'approved by staff'),
- meta.ForeignKey(core.Site),
- )
- ordering = ('-submit_date',)
- admin = meta.Admin(
- fields = (
- (None, {'fields': ('content_type_id', 'object_id', 'site_id')}),
- ('Content', {'fields': ('person_name', 'comment')}),
- ('Meta', {'fields': ('submit_date', 'is_public', 'ip_address', 'approved')}),
- ),
- list_display = ('person_name', 'submit_date', 'content_type_id', 'get_content_object'),
- list_filter = ('submit_date',),
- date_hierarchy = 'submit_date',
- search_fields = ('comment', 'person_name'),
- )
+ # A FreeComment is a comment by a non-registered user.
+ content_type = meta.ForeignKey(core.ContentType)
+ object_id = meta.IntegerField('object ID')
+ comment = meta.TextField(maxlength=3000)
+ person_name = meta.CharField("person's name", maxlength=50)
+ submit_date = meta.DateTimeField('date/time submitted', auto_now_add=True)
+ is_public = meta.BooleanField()
+ ip_address = meta.IPAddressField()
+ # TODO: Change this to is_removed, like Comment
+ approved = meta.BooleanField('approved by staff')
+ site = meta.ForeignKey(core.Site)
+ class META:
+ db_table = 'comments_free'
+ ordering = ('-submit_date',)
+ admin = meta.Admin(
+ fields = (
+ (None, {'fields': ('content_type', 'object_id', 'site')}),
+ ('Content', {'fields': ('person_name', 'comment')}),
+ ('Meta', {'fields': ('submit_date', 'is_public', 'ip_address', 'approved')}),
+ ),
+ list_display = ('person_name', 'submit_date', 'content_type', 'get_content_object'),
+ list_filter = ('submit_date',),
+ date_hierarchy = 'submit_date',
+ search_fields = ('comment', 'person_name'),
+ )
def __repr__(self):
return "%s: %s..." % (self.person_name, self.comment[:100])
@@ -203,26 +199,25 @@ def get_content_object(self):
get_content_object.short_description = 'Content object'
class KarmaScore(meta.Model):
- module_name = 'karma'
- fields = (
- meta.ForeignKey(auth.User),
- meta.ForeignKey(Comment),
- meta.SmallIntegerField('score', 'score', db_index=True),
- meta.DateTimeField('scored_date', 'date scored', auto_now=True),
- )
- unique_together = (('user_id', 'comment_id'),)
- module_constants = {
- # what users get if they don't have any karma
- 'DEFAULT_KARMA': 5,
- 'KARMA_NEEDED_BEFORE_DISPLAYED': 3,
- }
+ user = meta.ForeignKey(auth.User)
+ comment = meta.ForeignKey(Comment)
+ score = meta.SmallIntegerField(db_index=True)
+ scored_date = meta.DateTimeField(auto_now=True)
+ class META:
+ module_name = 'karma'
+ unique_together = (('user', 'comment'),)
+ module_constants = {
+ # what users get if they don't have any karma
+ 'DEFAULT_KARMA': 5,
+ 'KARMA_NEEDED_BEFORE_DISPLAYED': 3,
+ }
def __repr__(self):
return "%d rating by %s" % (self.score, self.get_user())
def _module_vote(user_id, comment_id, score):
try:
- karma = get_object(comment_id__exact=comment_id, user_id__exact=user_id)
+ karma = get_object(comment__id__exact=comment_id, user__id__exact=user_id)
except KarmaScoreDoesNotExist:
karma = KarmaScore(None, user_id, comment_id, score, datetime.datetime.now())
karma.save()
@@ -241,13 +236,12 @@ def _module_get_pretty_score(score):
return int(round((4.5 * score) + 5.5))
class UserFlag(meta.Model):
- db_table = 'comments_user_flags'
- fields = (
- meta.ForeignKey(auth.User),
- meta.ForeignKey(Comment),
- meta.DateTimeField('flag_date', 'date flagged', auto_now_add=True),
- )
- unique_together = (('user_id', 'comment_id'),)
+ user = meta.ForeignKey(auth.User)
+ comment = meta.ForeignKey(Comment)
+ flag_date = meta.DateTimeField(auto_now_add=True)
+ class META:
+ db_table = 'comments_user_flags'
+ unique_together = (('user', 'comment'),)
def __repr__(self):
return "Flag by %r" % self.get_user()
@@ -261,7 +255,7 @@ def _module_flag(comment, user):
if int(comment.user_id) == int(user.id):
return # A user can't flag his own comment. Fail silently.
try:
- f = get_object(user_id__exact=user.id, comment_id__exact=comment.id)
+ f = get_object(user__id__exact=user.id, comment__id__exact=comment.id)
except UserFlagDoesNotExist:
from django.core.mail import mail_managers
f = UserFlag(None, user.id, comment.id, None)
@@ -270,13 +264,12 @@ def _module_flag(comment, user):
f.save()
class ModeratorDeletion(meta.Model):
- db_table = 'comments_moderator_deletions'
- fields = (
- meta.ForeignKey(auth.User, verbose_name='moderator'),
- meta.ForeignKey(Comment),
- meta.DateTimeField('deletion_date', 'date deleted', auto_now_add=True),
- )
- unique_together = (('user_id', 'comment_id'),)
+ user = meta.ForeignKey(auth.User, verbose_name='moderator')
+ comment = meta.ForeignKey(Comment)
+ deletion_date = meta.DateTimeField(auto_now_add=True)
+ class META:
+ db_table = 'comments_moderator_deletions'
+ unique_together = (('user', 'comment'),)
def __repr__(self):
return "Moderator deletion by %r" % self.get_user()
@@ -123,7 +123,7 @@ def render(self, context):
self.obj_id = template.resolve_variable(self.context_var_name, context)
comment_count = get_count_function(object_id__exact=self.obj_id,
content_type__package__label__exact=self.package,
- content_type__python_module_name__exact=self.module, site_id__exact=SITE_ID)
+ content_type__python_module_name__exact=self.module, site__id__exact=SITE_ID)
context[self.var_name] = comment_count
return ''
@@ -146,7 +146,7 @@ def render(self, context):
'object_id__exact': self.obj_id,
'content_type__package__label__exact': self.package,
'content_type__python_module_name__exact': self.module,
- 'site_id__exact': SITE_ID,
+ 'site__id__exact': SITE_ID,
'select_related': True,
'order_by': (self.ordering + 'submit_date',),
}
@@ -86,8 +86,8 @@ def get_comment(self, new_data):
def save(self, new_data):
today = datetime.date.today()
c = self.get_comment(new_data)
- for old in comments.get_list(content_type_id__exact=new_data["content_type_id"],
- object_id__exact=new_data["object_id"], user_id__exact=self.get_user_id()):
+ for old in comments.get_list(content_type__id__exact=new_data["content_type_id"],
+ object_id__exact=new_data["object_id"], user__id__exact=self.get_user_id()):
# Check that this comment isn't duplicate. (Sometimes people post
# comments twice by mistake.) If it is, fail silently by pretending
# the comment was posted successfully.
@@ -141,7 +141,7 @@ def save(self, new_data):
# Check that this comment isn't duplicate. (Sometimes people post
# comments twice by mistake.) If it is, fail silently by pretending
# the comment was posted successfully.
- for old_comment in freecomments.get_list(content_type_id__exact=new_data["content_type_id"],
+ for old_comment in freecomments.get_list(content_type__id__exact=new_data["content_type_id"],
object_id__exact=new_data["object_id"], person_name__exact=new_data["person_name"],
submit_date__year=today.year, submit_date__month=today.month,
submit_date__day=today.day):
@@ -16,7 +16,7 @@ def flag(request, comment_id):
the flagged `comments.comments` object
"""
try:
- comment = comments.get_object(pk=comment_id, site_id__exact=SITE_ID)
+ comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID)
except comments.CommentDoesNotExist:
raise Http404
if request.POST:
@@ -31,7 +31,7 @@ def flag(request, comment_id):
def flag_done(request, comment_id):
try:
- comment = comments.get_object(pk=comment_id, site_id__exact=SITE_ID)
+ comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID)
except comments.CommentDoesNotExist:
raise Http404
t = template_loader.get_template('comments/flag_done')
@@ -50,7 +50,7 @@ def delete(request, comment_id):
the flagged `comments.comments` object
"""
try:
- comment = comments.get_object(pk=comment_id, site_id__exact=SITE_ID)
+ comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID)
except comments.CommentDoesNotExist:
raise Http404
if not comments.user_is_moderator(request.user):
@@ -72,7 +72,7 @@ def delete(request, comment_id):
def delete_done(request, comment_id):
try:
- comment = comments.get_object(pk=comment_id, site_id__exact=SITE_ID)
+ comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID)
except comments.CommentDoesNotExist:
raise Http404
t = template_loader.get_template('comments/delete_done')
Oops, something went wrong.

0 comments on commit 25264c8

Please sign in to comment.