Questions tagged [django-generic-relations]

44 questions
0
votes
1 answer

Check content type with if statement to determine what to do

I have django model with a generic relation associated. class SectionLine(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) ... content_type = models.ForeignKey(ContentType,…
0
votes
2 answers

How to get an object after been created using CreateView inside django CBV

am trying to create a notification system that tracks all the activities of my users. to achieve this I have created two models, The Contribution model and Notifition model class Contribution(models.Model): slug = …
0
votes
1 answer

How to add likes to my blog posts using generic relationships in Django

I'm trying to add a like/dislike functionality in Django using generic relationships. Can someone help me? My post model class Post(models.Model): title = models.CharField(max_length=225) post_image = models.ImageField(null=True,…
FDodaj
  • 17
  • 1
  • 4
0
votes
0 answers

How to post to HyperlinkedRelatedField in Django Rest Framework?

Here I have two models called PostComment and AnswerComment separately to handle comments in my web application. Now I need to have voting option for both Post and Answer comments. Therefore I though using Django GenericRelations here would be a…
0
votes
1 answer

Django - how to build a GenericRelation query?

I'm trying to access all my different model objects by the Hit table. What I do not understand is why I'm unable to Build the actual query to do that. I simply want to get all objects at queryset_m1-m3 where the Model1-3.pk is the hit.object_id as…
user14389292
0
votes
1 answer

Django Generic Relation woth parent model

I have created a model Comments. I want store reply in same table Comment. class Comment(models.Model): user = models.ForeignKey(User, blank=True, null=True, on_delete=models.CASCADE) content_type = models.ForeignKey(ContentType,…
0
votes
1 answer

Generic relation in Django rest

Problem I want to create Student With Address. How can I write REST API in Django for same. Address & Student class Address(models.Model): address = models.CharField(max_length=100, null=False, blank=False) land_mark =…
0
votes
1 answer

How to access objects of grandparent model associated with target model through ContentType GenericForeignKey?

I'm trying to filter objects of model based on associated grandparent model. They are associated with each other through an intermediary parent model. Parent model is associated with grandparent through ContentType GenericForeignKey. How can I…
0
votes
1 answer

How to filter taggit tags with related items fields using the Django ORM?

I have a model where I use the django-taggit TaggableManager: from django.db import models from model_utils import Choices from taggit_autosuggest.managers import TaggableManager LANGUAGE_CHOICES = Choices( ('de', 'Allemand - Deutch'), …
Natim
  • 17,274
  • 23
  • 92
  • 150
0
votes
1 answer

Django ORM - building hierarchical data structure with multiple models

as a part of a project I'm working on, I'm trying to build an hierarchical data structure of objects from different types. I used django-mptt for it, which promises to handle trees in a smart way with fast queries. The problem is, that I have…
0
votes
2 answers

Django not see the table in generic relation

I'm working with Django 1.7.2 with generic relation (reason: project has two databases), and after import I don't want to have overwritten database. I want to show only active season Here is my model, is overwritten after import: class…
Mark
  • 15
  • 1
  • 6
0
votes
1 answer

Generic relation in django, queryset with aggregate

I use django 1.6 and generic relation in models. And I have problem with aggregate function in model: Here is part of my view: class EventListView(PageContextMixin, ListView): model = Activity template_name = 'events/eventlist.html' def…
0
votes
1 answer

Django query caching through a ForeignKey on a GenericRelation

Using a GenericRelation to map Records to Persons, I have the following code, which works correctly, but there is a performance problem I am trying to address: models.py class RecordX(Record): # Child class .... class Record(models.Model): #…
TAH
  • 1,658
  • 1
  • 19
  • 37
-1
votes
1 answer

How to make multiple types of models and refer them with same name in Django?

I am new to Django. I want the functionality of Accounts and Transactions. Account can have three types of transactions. Income, Expense and Transfer. All of them have some common fields among them. But also have some additional fields. I want to…
1 2
3