Is it safe to refactor my django models?

My model is similar to this one. Is this ok or should I make the generic base class abstract? What are the differences between this or making it abstract and not having an extra table? It seems strange that there is now only one primary key that I have.

class Input(models.Model):
        details = models.CharField(max_length=1000)
        user = models.ForeignKey(User)
        pub_date = models.DateTimeField('date published')
        rating = models.IntegerField()

        def __unicode__(self):
            return self.details

    class Case(Input):
        title  = models.CharField(max_length=200)
        views = models.IntegerField()

    class Argument(Input):
        case = models.ForeignKey(Case)
        side = models.BooleanField()

      

is it ok to comment out the intpu Input? I noticed that cases and arguments have a common key.

like this:

    CREATE TABLE "cases_input" (
        "id" integer NOT NULL PRIMARY KEY,
        "details" varchar(1000) NOT NULL,
        "user_id" integer NOT NULL REFERENCES "auth_user" ("id"),
        "pub_date" datetime NOT NULL,
        "rating" integer NOT NULL
    )
    ;
    CREATE TABLE "cases_case" (
        "input_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "cases_input" ("id"),
        "title" varchar(200) NOT NULL,
        "views" integer NOT NULL
    )
    ;
    CREATE TABLE "cases_argument" (
        "input_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "cases_input" ("id"),
        "case_id" integer NOT NULL REFERENCES "cases_case" ("input_ptr_id"),
        "side" bool NOT NULL
    )

      

+1


a source to share


1 answer


From: django website



Abstract base classes are useful when you want to put some general information on top of other models. You write your base class and put abstract = True in the Meta class. This model will not be used to create any database table. Instead, when it is used as a base class for other models, its fields will be added to the fields of the child class.

+1


a source







All Articles