Questions tagged [model-inheritance]
14 questions
5
votes
3 answers
Enforce auto_now when using save(update_fields = […])
Model definitions:
class Footprint(models.Model)
date = models.DateTimeField(auto_now = True)
class Stuff(Footprint):
name = models.CharField(max_length = 255)
some_other_field = models.CharField(max_length = 255)
In a Stuff object, I'd like…

alexpirine
- 3,023
- 1
- 26
- 41
4
votes
2 answers
Model inheritance approach with Django's ORM
I want to store events in a web application I am fooling around with and I feel quite unsure about the pros and cons of each respective approach - using inheritance extensively or in a more modest manner.
Example:
class Event(models.Model):
…

mojbro
- 1,509
- 13
- 13
2
votes
3 answers
How can I query a model by if there is a subclass instance?
I have these two simple models, A and B:
from django.db import models
class A(models.Model):
name = models.CharField(max_length=10)
class B(A):
age = models.IntegerField()
Now, how can I query for all instances of A which do not have an…

ironfroggy
- 7,991
- 7
- 33
- 44
2
votes
1 answer
Specifying initial field values for ModelForm associated with inherited models
Question : What is the recommended way to specify an initial value for fields if one uses model inheritance and each child model needs to have different default values when rendering a ModelForm?
Take for example the following models where…

Shawn Chin
- 84,080
- 19
- 162
- 191
2
votes
0 answers
Django model for same structured databases
I have different data databases of same database schema (also in 1 database: different tables with same structure/schema) and I want use those databases in all my other apps as data backend.
For example,
database name: database1
class…

user2656976
- 21
- 2
1
vote
1 answer
Django: Orphan parent instances when saving of child fails
I have a Photo class which inherits from Content model like this:
class Content(models.Model):
added = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
class Photo(Content):
file =…

onurmatik
- 5,105
- 7
- 42
- 67
0
votes
0 answers
Django Model inheritance: model child class creating extra rows in model parent class data-table
I am trying to apply basic model inheritance based on the Django documentation. The end goal is to access the shared id of the Exam and Date models in the get_date_info view, which is called after the get_exam_info view. Perhaps there is a better…

Michael Snyder
- 1
- 1
0
votes
1 answer
Problem inheriting get_absolute_url in an child model
I have the following sets of models (abbreviated for clarity):
First set:
class Web(Link):
ideas = models.ManyToManyField(Idea, blank=True, null=True)
precedents = models.ManyToManyField(Precedent, blank=True, null=True)
categories =…

Douglas Meehan
- 13
- 4
0
votes
2 answers
Django inheritance
Please have a look:
class Categorie(models.Model):
id = models.AutoField('id', primary_key=True)
title = models.CharField('title', max_length=800)
articles = models.ManyToManyField(Article)
class Article(models.Model):
id =…

Martin Magakian
- 3,746
- 5
- 37
- 53
0
votes
1 answer
Which type of model inheritance to choose in Django
I am trying to write models for an inventory-type project in Django and am unsure how to best define my models. Do I choose Abstract Base Classes, Multi-Table Inheritance, Proxy Models or something else to get my models to behave according to these…

funkymonk012
- 11
- 1
0
votes
1 answer
Django increment ID in each subclass model individually
There is an old code with two models shown as below:
class Watermelon(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64, default='Unnamed Watermelon')
is_allegic =…

benny
- 1
- 2
0
votes
3 answers
Storing data in different tables or using bool fields
I have an Article table
class Article(models.Model):
"""
Model to keep articles
"""
ext_id = models.UUIDField(primary_key=True, db_index=True, default=uuid.uuid4, editable=False)
title = models.CharField(max_length=255,…

Deepankar Bajpeyi
- 5,661
- 11
- 44
- 64
0
votes
1 answer
Rails model inheritance with unique sets of fields
I have a model BillService with basic set of fields. Next I want to create two models BillItem and BillGroup, which are the heirs of this and have the additional fields (each has a unique set). I also want to be able to get through the base class…

Alexander Likhachev
- 11
- 3
0
votes
0 answers
Rails model structure for user created league tables
I'm looking to build an application that will allow multiple users to create their own tables, populate those tables with fields and 'contestants'.
I'm trying to piggyback off of the work I did following the rails tutorial…

Kali_89
- 617
- 2
- 7
- 21