Hello, 

I am trying to develop an employee schedule based on upcoming events and I 
only need to make additions or updates in Django Admin. To add a new event 
I would like to pick from a drop down list of only the events that are in 
the future or on todays date not the entire table list of events that may 
go back several years. I would do normally do this in a view like this ....

events  = 
WineryEvents.objects.filter(publish='Y').filter(event_date__gte=datetime.now()).order_by('event_date')

However, I am unsure of how to do this in my main/admin.py. 

The drop down list would ideally be ordered by date and only for future or 
current events and formatted like this...

(EVENT DATE MM/DD/YY EVENT TITLE)  

Could someone help me out with the code to put in the main/admin.py to 
accomplish this? Model and admin.py info below...

main/models.py

class EmployeeSchedule(models.Model):
    user = models.ForeignKey(CustomUser, on_delete=models.PROTECT, 
blank=True,  null=True)
    event = models.ForeignKey(WineryEvents, on_delete=models.PROTECT)
    role = models.CharField(choices=ROLE, max_length=40)
    start_time = models.TimeField(auto_now_add=False)
    comment = models.TextField(blank=True)

    def __str__(self):
       return self.role

restaurant/models.py

class WineryEvents(models.Model):
   event_date = models.DateField(auto_now_add=False)
   event_time = models.TimeField(auto_now_add=False)
   event_type = models.CharField(max_length=20, choices=EVENT_TYPE)
   seating = models.PositiveIntegerField(default=0)
   title = models.CharField(max_length=200)
   description = models.TextField()
   menu = models.TextField()
   price = models.DecimalField(max_digits=6, decimal_places=2)
   publish = models.CharField(max_length=1, choices=PUBLISH_CHOICE)

   def __str__(self):
      return self.title

And the following main/admin.py

class EmployeeScheduleAdmin(admin.ModelAdmin):

   def user_info(self, obj):
     return obj.user.get_full_name()

   list_display = ['event','user_info','role', 'start_time']
   list_filter = ['event','user']
   ordering = ['-event']

admin.site.register(models.EmployeeSchedule, EmployeeScheduleAdmin)

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/99224469-d2ed-4085-a2b6-c7676843fff7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to