DEV Community

Discussion on: How can I make a list of group data by month-year in rest Framework with json output?

Collapse
 
tipu profile image
Borhan Tipu

My Model Is

class Event(models.Model):
title = models.CharField(max_length=255, default=None, unique=True)
description = models.TextField()
date = models.DateField(default=None, null=True)

I want to group the from the date field with month-year( like 01-2017 or JAN-2017)

I see that you created another model for that. Can I do it with single model?

Collapse
 
lord007tn profile image
Raed Bahri

yeah you can but as a best practice if you have a data that require more than one field just put it in a class and refer to it as a foreign key

so it will be a class for your event that have date and name
and a class for group of event or category that take events as foreign keys
in django admin you can control that easily

Thread Thread
 
tipu profile image
Borhan Tipu

Ok. Let me try this. If it is worked that would be great