Hi everyone! :)
I just stumbled upon the hardest problem I ever had with Django Rest
Framework. Let me give you my models first, and then explain:
class Stampcardformat(models.Model):
workunit = models.ForeignKey(
Workunit,
on_delete=models.CASCADE
)
uuid = models.UUIDField(
default=uuid.uuid4,
editable=False,
unique=True
)
limit = models.PositiveSmallIntegerField(
default=10
)
category = models.CharField(
max_length=255
)
class Stampcard(models.Model):
stampcardformat = models.ForeignKey(
Stampcardformat,
on_delete=models.CASCADE
)
user = models.ForeignKey(
User,
on_delete=models.CASCADE
)
uuid = models.UUIDField(
default=uuid.uuid4,
editable=False,
unique=True
)
class Stamp(models.Model):
stampcardformat = models.ForeignKey(
Stampcardformat,
on_delete=models.CASCADE
)
stampcard = models.ForeignKey(
Stampcard,
on_delete=models.CASCADE,
blank=True,
null=True
)
uuid = models.UUIDField(
default=uuid.uuid4,
editable=False,
unique=True
)
These models describe a simple stampcard model. A stampcard is considered
full, when it has as many stamps via foreignkey associated to it as it's
stampcardformat's limit number dictates.
I need to write view that does the following:
1. The view takes in a list of stamps (see below) consisting of their
uuid's.
2. It then needs to find the right stampcardformat for each given stamp.
3. Next it needs to *check, whether the requests user has a stampcard
with the corresponding stampcardformat*.
a) *If it has* it needs to check, *if the stampcard is full or not.*
i) *If it is full*, it needs to create a new stampcard of the given
format and update the stamps stampcard-foreignkey to the created stampcard.
ii) *If it isn't full* t needs update the stamps stampcard-foreignkey to
the found stampcard
b) *If the user hasn't got a stampcard* of the given stampcardformat, it
needs to create a new stampcard and update the stamps stampcard-foreignkey
to the created stampcard.
This is probably a easy question for a real Django Pro, but for me it feels
like a impossible challenge. The class based views don't seem to support
this behaviour. I tried modifying the class based views, to no avail. I
fail besides many points, because the view throws the error:
AssertionError: Expected view StampUpdate to be called with a URL keyword
argument named "pk". Fix your URL conf, or set the `.lookup_field`
attribute on the view correctly.
Any help would be much appreciated!
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.