Last active
August 29, 2015 14:23
-
-
Save exit99/17b4f16d56338949cf0f to your computer and use it in GitHub Desktop.
On django==1.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductCategory(models.Model): | |
name = models.CharField(max_length=50) | |
priority = models.IntegerField() | |
slug = models.CharField(max_length=50, unique=True) | |
class Meta: | |
ordering = ['priority'] | |
class AbstractProduct(models.Model): | |
categories = models.ManyToManyField(ProductCategory) | |
class Meta: | |
abstract=True | |
class Product(AbstractProduct): | |
pass | |
class PlanSnapShot(AbstractProduct): | |
name = models.CharField(max_length=255) | |
base_discount = models.FloatField(null=True, blank=True) | |
# The following error is given when executing `<plansnapshot object>.categories.all()` with `<plansnapshot object>` being any instance of the class | |
FieldError: Cannot resolve keyword u'plansnapshot' into field. Choices are: id, name, priority, product, slug | |
# Yet when I run the same code in `shell`. The relationship works and no errors are thrown. I am scratching my head here. | |
# Here is additional Information | |
# ############################## | |
# If I print `<plansnapshot object>.categories` they are the same in both the application and the shell. | |
# I have tried importing both `Product` and `PlanSnapShot` and not importing the other. Everything works in the shell regardless. | |
# `<product object>.categories.all()` works in the application and the shell. | |
# I have tried adding a generic property to `PlanSnapShot`. I can access that property in both the application and the shell without having to restart the application. | |
# Tried putting unique many to many fields in the two inheriting models instead of the abstract class. When running an --auto migration in south I get this return | |
- Deleted model cart.GoldenPlan | |
- Deleted model cart.PlanSnapShot | |
- Deleted M2M table for categories on cart.PlanSnapShot | |
- Deleted model cart.StoreDisplay | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment