is it safe to refactor my django models?

Posted by Johnd on Stack Overflow See other posts from Stack Overflow or by Johnd
Published on 2009-05-11T04:43:09Z Indexed on 2010/05/03 11:08 UTC
Read the original article Hit count: 174

Filed under:

My model is similar to this. Is this ok or should I make the common base class abstract? What are the differcenes between this or makeing it abstract and not having an extra table? It seems odd that there is only one primary key now that I have factored stuff out.

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 this ok to factor stuff out intpu Input? I noticed Cases and Arguments share a primary 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
    )

© Stack Overflow or respective owner

Related posts about django-models