I apologise if this is a simple question but I am still somewhat new to Dajngo.
I have the following models:
Jobs Model
Candidates Model
Applications Model
The jobs model has a manager on it as follows:
class ExpiredManager(models.Manager):
def get_queryset(self):
return super(ExpiredManager, self).get_queryset() \
.filter(expiry_date__gt=datetime.now()).order_by('start_date')
And to make sure only unexpired items are listed on the web page my managers are listed as follows:
objects = ExpiredManager()
with_expired_objects = models.Manager()
Within my admin I have the following:
def get_queryset(self, request):
"""To return all jobs in admin including those that are expired"""
qs = self.model.with_expired_objects.get_queryset()
ordering = self.get_ordering(request)
if ordering:
qs = qs.order_by(*ordering)
return qs
At this stage evrything works exactly as I want it to with all jobs being shown in the admin and only unexpired jobs on the web page.
My candidates model has the following field:
jobs = models.ManyToManyField('jobs.Job', through="applications.Application")
My application model has fields for candidate and jobs.
My problem is that once the job expires it is being dropped from both the candidates and the applications as obviously the expired items manager is the default.
Any help on how to correct this would be appreciated.
Many thanks
-- I have the following models:
Jobs Model
Candidates Model
Applications Model
The jobs model has a manager on it as follows:
class ExpiredManager(models.Manager):
def get_queryset(self):
return super(ExpiredManager, self).get_queryset() \
.filter(expiry_date__gt=datetime.now()).order_by('start_date')
And to make sure only unexpired items are listed on the web page my managers are listed as follows:
objects = ExpiredManager()
with_expired_objects = models.Manager()
Within my admin I have the following:
def get_queryset(self, request):
"""To return all jobs in admin including those that are expired"""
qs = self.model.with_expired_objects.get_queryset()
ordering = self.get_ordering(request)
if ordering:
qs = qs.order_by(*ordering)
return qs
At this stage evrything works exactly as I want it to with all jobs being shown in the admin and only unexpired jobs on the web page.
My candidates model has the following field:
jobs = models.ManyToManyField('jobs.Job', through="applications.Application")
My application model has fields for candidate and jobs.
My problem is that once the job expires it is being dropped from both the candidates and the applications as obviously the expired items manager is the default.
Any help on how to correct this would be appreciated.
Many thanks
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/a9349301-03db-4793-856b-b62836854de9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment