B
B
Boldy2015-07-24 10:20:23
Django
Boldy, 2015-07-24 10:20:23

How to use ForeignKey with abstract base class in django?

I want this:

class A(models.Model):
    class Meta: 
        abstract = True

class B(A):
    pass

class C(A):
    pass

class D(models.Model):
    a = models.ForeignKey(A)

    def is_b(self):
        return if isinstance(self.a, b):

But when creating migrations, jang complains that it cannot create a ForeignKey for an abstract class. How is it solved?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oscar Django, 2015-07-24
@Boldy

Don't make the class abstract.

U
un1t, 2015-07-24
@un1t

The abstract class does not create a table, how do you think it should work at the database level?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question