Display objects from different models at the same page according to their published date

28 views
Skip to first unread message

Aamu Padi

unread,
Jun 10, 2016, 11:42:45 AM6/10/16
to django...@googlegroups.com
I have three different models for my app. All are working as I expected. 

    class Tender(models.Model):
        title = models.CharField(max_length=256)
        description = models.TextField()
        department = models.CharField(max_length=50)
        address = models.CharField(max_length=50)
        nature_of_work = models.CharField(choices=WORK_NATURE, max_length=1)
        period_of_completion = models.DateField()
        pubdat = models.DateTimeField(default=timezone.now)    
    
    class Job(models.Model):
        user = models.ForeignKey(settings.AUTH_USER_MODEL)
        title = models.CharField(max_length=256)
        qualification = models.CharField(max_length=256)
        interview_type = models.CharField(max_length=2, choices=INTERVIEW_TYPE)
        type_of_job = models.CharField(max_length=1, choices=JOB_TYPE)
        number_of_vacancies = models.IntegerField()
        employer = models.CharField(max_length=50)
        salary = models.IntegerField()    
        pubdat = models.DateTimeField(default=timezone.now)
    
    class News(models.Model):
        user = models.ForeignKey(settings.AUTH_USER_MODEL)
        title = models.CharField(max_length=150)
        body = models.TextField()
        pubdat = models.DateTimeField(default=timezone.now)

Now I am displaying each of them at separate page for each of the model (e.g. in the *jobs* page, I am displaying only the jobs.). But now at the home page, I want to display these according to their published date at the same page. How can I display different objects from different models at the same page? Do I make a separate model e.g. `class Post` and then use signal to create a new post whenever a new object is created from `Tender`, or `Job`, or `News`? I  really hope there is a better way to achieve this. Please help me. Thank you.

Virus-free. www.avast.com

Aamu Padi

unread,
Jun 10, 2016, 11:59:55 AM6/10/16
to django...@googlegroups.com
This is just a follow up of my question.

I don't want to show each of the model objects separately at the same page. But like feeds of facebook or any other social media. Suppose a new Job object was created, and after that a new News object is created. Then, I want to show the News object first, and then the Job object, and so on.

Rafael Guillén

unread,
Jun 10, 2016, 2:39:50 PM6/10/16
to Django users
Instead of making them entirely separate models, you can use one model as a base and have the other models inherit from them, then you display the base model. I think this might be a good fit for multi-table inheritance. See if this helps:

https://docs.djangoproject.com/en/1.9/topics/db/models/#model-inheritance

Aamu Padi

unread,
Jun 10, 2016, 4:17:51 PM6/10/16
to django...@googlegroups.com
Yes, I too was thinking about that. I had doubts about the space and the performance of it. Do you see any downside \on the space and performance?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d0ba3060-a7ae-4837-9d23-c5a652ef6bb5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages