Open s1liconcow opened 1 week ago
I haven't quite figured out why this is broken but fwiw it seems you can 'hack' this to work with:
from django_unicorn.components import UnicornView, QuerySetType
from frontend.models import Resource, ResourceType
class TestView(UnicornView):
resource: Resource = None
resources: QuerySetType[Resource] = None
def mount(self):
self.resources = Resource.objects.all()
self.resource = self.resources[0]
def load(self):
self.resource = self.resources[1]
def save(self):
print(self.resource.name)
Bug Description
I'm trying to make a view where the user can select a model and edit it. If I load the model in mount(), this works as expected. However if I try to load the model in another method, it doesn't seem to be able to deserialize it when the user saves (or does anything):
Expected behaviour
Can use a model loaded outside of 'mount'.
Screenshots / Screenrecords
see below
Steps to reproduce
Example repro
The view doesn't really matter but:
Clicking 'save' will cause it to throw the above exception. The Resource.type is a ForeignKey to ResourceType.
This, however, works:
What browsers are you seeing the problem on?
Chrome
👀 Have you checked for similar open issues?
Code of Conduct
Are you willing to work on this issue ?
Yes I am willing to submit a PR!