Hi,
I think finding solution to this can consume time. Simply make a function
which will change the user reference of the card over a given period of
time.


Regards
Dev

On Mon 8 Oct, 2018, 10:47 PM Derek, <gamesb...@gmail.com> wrote:

> Apart from setting up a unique key (user, card, start, end), you may also
> want to check if the date range for that card overlaps with another date
> range; e.g. see
> https://stackoverflow.com/questions/9044084/efficient-date-range-overlap-calculation-in-python
> --> do that check in the clean method and return an error if the system
> tries to allocate the card when its already (partly) used in the same time
> period.  If you have other restrictions (like not being being assign cards
> "in the past") that will also help cut down on invalid assignments.
>
> On Monday, 8 October 2018 13:10:04 UTC+2, Shareef 617 wrote:
>>
>> Consider a project where users can have many cards (or anything else,
>> card is just an example), and the same card can belong to multiple users *but
>> only in different time periods*. So if a card is assigned to user from
>> 1.09.2014 to 1.10.2014 (dd/mm/yyyy), then the same card can be assigned to
>> another user but only for time period that ends before 1.09.2014 or starts
>> after 1.10.2014. I hope you get it.
>>
>> I've created the following models:
>>
>> class User(models.Model):
>>     cards = models.ManyToManyField(Card, through="UsersCards")
>>
>> class UsersCards(models.Model):
>>     user = models.ForeignKey(User)
>>     card = models.ForeignKey(Card)
>>     start_date = models.DateField()
>>     end_date = models.DateField()
>>
>> --
> 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+unsubscr...@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/0657b0f6-eded-4566-929a-415459e346eb%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/0657b0f6-eded-4566-929a-415459e346eb%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CALZ%3DbEK7AFDCjAKUyJOt0qU0BeFyZbF9Snf%2B%3De-QtO8%3Dh-AmYA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to