make reviews.version optional, attach an addon id

This commit is contained in:
Jeff Balogh 2010-06-03 12:50:15 -07:00
Родитель b91f84a09b
Коммит 5bcfae3945
7 изменённых файлов: 20 добавлений и 126 удалений

Просмотреть файл

@ -211,10 +211,12 @@ class TestAddonModels(test_utils.TestCase):
addon = Addon.objects.get(id=3615)
u = UserProfile.objects.get(pk=2519)
version = addon.current_version
new_review = Review(version=version, user=u, rating=2, body='hello')
new_review = Review(version=version, user=u, rating=2, body='hello',
addon=addon)
new_review.save()
new_reply = Review(version=version, user=addon.authors.all()[0],
reply_to=new_review, rating=2, body='my reply')
addon=addon, reply_to=new_review,
rating=2, body='my reply')
new_reply.save()
review_list = [r.pk for r in addon.reviews]

Просмотреть файл

@ -1,119 +0,0 @@
[
{
"pk": 2,
"model": "translations.translation",
"fields": {
"locale": "en-US",
"created": "2009-12-22 20:12:06",
"id": 2,
"modified": "2009-12-22 20:12:06",
"localized_string": "r1 title en"
}
},
{
"pk": 3,
"model": "translations.translation",
"fields": {
"locale": "de",
"created": "2009-12-22 20:12:06",
"id": 2,
"modified": "2009-12-22 20:12:06",
"localized_string": "r1 title de"
}
},
{
"pk": 4,
"model": "translations.translation",
"fields": {
"locale": "de",
"created": "2009-12-22 20:12:06",
"id": 3,
"modified": "2009-12-22 20:12:06",
"localized_string": "r2 title de"
}
},
{
"pk": 1,
"model": "users.userprofile",
"fields": {
"firstname": "",
"created": "2009-10-19 06:21:02",
"lastname": "",
"modified": "2009-10-19 06:21:02",
"nickname": "nobody",
"email": "nobody@mozilla.org"
}
},
{
"pk": 1,
"model": "addons.addontype",
"fields": {
"name": null,
"name_plural": null,
"description": null,
"modified": "2006-07-11 11:11:11",
"created": "2006-06-11 18:23:31"
}
},
{
"pk": 4,
"model": "addons.addon",
"fields": {
"type": 1,
"status": 4,
"highest_status": 4,
"description": null,
"modified": "2008-05-22 11:59:13",
"name": null,
"created": "2004-06-11 18:23:31"
}
},
{
"pk": 1,
"model": "versions.license",
"fields": {
"id": 1,
"_custom_text": null,
"modified": "2004-06-11 18:23:31",
"created": "2004-06-11 18:23:31"
}
},
{
"pk": 5,
"model": "versions.version",
"fields": {
"addon": 4,
"license": 1,
"modified": "2004-06-11 18:23:31",
"created": "2004-06-11 18:23:31"
}
},
{
"pk": 1,
"model": "reviews.review",
"fields": {
"body": null,
"rating": 4,
"title": 2,
"created": "2009-12-22 20:12:06",
"modified": "2009-12-22 20:12:06",
"version": 5,
"user": 1,
"reply_to": null
}
},
{
"pk": 2,
"model": "reviews.review",
"fields": {
"body": null,
"rating": 4,
"title": 3,
"created": "2009-12-22 20:12:06",
"modified": "2009-12-22 20:12:06",
"version": 5,
"user": 1,
"reply_to": null
}
}
]

Просмотреть файл

@ -11,7 +11,7 @@ from applications.models import Application
class TestRedirects(test.TestCase):
fixtures = ['amo/test_redirects', 'base/global-stats']
fixtures = ['reviews/test_models', 'base/global-stats']
def test_persona_category(self):
"""`/personas/film and tv` should go to /personas/film-and-tv"""

Просмотреть файл

@ -98,6 +98,7 @@
"created": "2009-12-22 20:12:06",
"modified": "2009-12-22 20:12:06",
"version": 5,
"addon": 4,
"user": 1,
"reply_to": null
}
@ -112,6 +113,7 @@
"created": "2009-12-22 20:12:06",
"modified": "2009-12-22 20:12:06",
"version": 5,
"addon": 4,
"user": 1,
"reply_to": null
}

Просмотреть файл

@ -8,8 +8,9 @@ from translations.models import Translation
class Review(TranslatedFieldMixin, amo.models.ModelBase):
version = models.ForeignKey('versions.Version', related_name='reviews')
addon = models.ForeignKey('addons.Addon', related_name='_reviews')
version = models.ForeignKey('versions.Version', related_name='reviews',
null=True)
user = models.ForeignKey('users.UserProfile', related_name='_reviews_all')
reply_to = models.ForeignKey('self', null=True, unique=True,
db_column='reply_to')

Просмотреть файл

@ -94,10 +94,11 @@ class TestUserProfile(test.TestCase):
addon = Addon.objects.get(id=3615)
u = UserProfile.objects.get(pk=2519)
version = addon.get_current_version()
new_review = Review(version=version, user=u, rating=2, body='hello')
new_review = Review(version=version, user=u, rating=2, body='hello',
addon=addon)
new_review.save()
new_reply = Review(version=version, user=u, reply_to=new_review,
body='my reply')
addon=addon, body='my reply')
new_reply.save()
review_list = [r.pk for r in u.reviews]

Просмотреть файл

@ -0,0 +1,7 @@
ALTER TABLE reviews
ADD COLUMN addon_id int(11) unsigned NULL,
ADD FOREIGN KEY (addon_id) REFERENCES addons (id),
CHANGE COLUMN version_id version_id int(11) unsigned NULL;
UPDATE reviews SET addon_id=
(SELECT addon_id FROM versions WHERE id=version_id);