Questions tagged [django-inheritance]
78 questions
122
votes
10 answers
In Django - Model Inheritance - Does it allow you to override a parent model's attribute?
I'm looking to do this:
class Place(models.Model):
name = models.CharField(max_length=20)
rating = models.DecimalField()
class LongNamedRestaurant(Place): # Subclassing `Place`.
name = models.CharField(max_length=255) # Notice, I'm…

Johnny 5
- 1,521
- 3
- 10
- 11
37
votes
3 answers
Django templates: overriding blocks of included children templates through an extended template
I'm wondering if anyone knows how to deal with the following quirky template structure:
### base.html
{% block title %} Title of the page {% endblock %}…

Chris Keele
- 3,364
- 3
- 30
- 52
11
votes
4 answers
Determining Django Model Instance Types after a Query on a Base-class
Is there a way to determine what the 'real' class of a Django database object is, after it has been returned from a query for on a base class?
For instance, if I have these models...
class Animal(models.Model):
name=…

Chris W.
- 37,583
- 36
- 99
- 136
7
votes
3 answers
Django inheritance and polymorphism with proxy models
I'm working on a Django project that I did not start and I am facing a problem of inheritance.
I have a big model (simplified in the example) called MyModel that is supposed to represents different kind of items.
All the instance objects of MyModel…

Leonardo
- 4,046
- 5
- 44
- 85
6
votes
1 answer
seperate 'admin' interfaces for different user types in django
I have recently being trying to create a project which has several levels of user involved.
(Just an example of an abbreviated and rough schema)
ME (Super User)
Client(s)
Customer(s)
Survey…

Pete Hamilton
- 7,730
- 6
- 33
- 58
5
votes
2 answers
Django select_related with fields specified breaks over multiple one to one relationships
I'm getting a weird error trying to select_related over multiple OneToOneField relationships, e.g. in the case where the target field is a grandchild subclass. I'd love someone to help me understand what's going on (or confirm that this is a bug in…

rfrankel
- 675
- 8
- 20
5
votes
2 answers
how to associate existing parent with child in django multitable inheritance
I have an existing parent entity with many existing records:
class Entity(models.Model):
name = models.CharField('Name', max_length=64, db_index=True)
I also have child objects that extend using django multi table inheritance:
class…

Atma
- 29,141
- 56
- 198
- 299
5
votes
3 answers
id of object is none after save in django
I'm looping through a list of objects and saving. I need the newly generated id or pointer id right after the save but it is None.
Here is my code:
for category in category_list:
saved_category = category.save()
print…

Atma
- 29,141
- 56
- 198
- 299
5
votes
4 answers
django renders a blank page
Firstly, I'd like to admit, I'm a completely new to Django. I'm learning as best as I can. I am working my way through a book called "Beginning Django E-Commerce". Without wishing to breach the copy right, perhaps you guys can spot where I have gone…

LeeO
- 71
- 3
- 9
4
votes
2 answers
Is it possible to make multi-level template inheritance in django templates?
I have three html-files:
base.html
page.html
comment.html
in page.html I extend base.html. In comment.html I extend page.html. Will comment.html extend base.html's blocks?

megido
- 4,135
- 6
- 29
- 33
4
votes
4 answers
Inheritance model update to its parent model
I need extend a model from another model.
Case:
core/models.py
class Master(models.Model):
code = models.CharField(max_length=30, unique=True)
name = models.CharField(max_length=100, blank=False, null=False)
class Meta:
abstract…

oegpyg
- 103
- 7
4
votes
1 answer
Django's MutiTable Vs. Abstract Inheritance
While there is general consensus that multi-table inheritance isn't a very good idea in the long term (Jacobian, Others), am wondering if in some use cases the "extra joins" created by django during querying might be worth it.
My issue is having a…

lukik
- 3,919
- 6
- 46
- 89
4
votes
2 answers
Django filter queryset by attribute subclass
I have a Slug model to identify Page objects. A BlogPost inherits from Page. I want to find a BlogPost given a Slug name, but no other Page objects.
EDIT: added models
class Slug(models.Model):
name = models.CharField()
page =…

jozxyqk
- 16,424
- 12
- 91
- 180
4
votes
1 answer
How to provide a default value for base class attribute from subclass in Django?
Scenario:
class BaseClass(models.Model):
base_field = models.CharField(max_length=15, default=None)
class SubClass(BaseClass):
# TODO set default value if base_field's value is None
...
ie. I need to be able to load a fixture into the…

mkelley33
- 5,323
- 10
- 47
- 71
4
votes
1 answer
Subclassing AbstractUser in Django for two types of users
I'm developing a school database system in Django 1.5, and was planning on having a number of different user types (Student, Staff, Parent) which subclass AbstractUser (actually, another abstract subclass of AbstractUser). I was just attempting to…

askvictor
- 3,621
- 4
- 32
- 45