Skip to content

one2one/parent models' fields are not serialized #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nerdoc opened this issue Oct 26, 2022 · 3 comments
Closed

one2one/parent models' fields are not serialized #459

nerdoc opened this issue Oct 26, 2022 · 3 comments
Assignees

Comments

@nerdoc
Copy link
Contributor

nerdoc commented Oct 26, 2022

I have a model

# models.py
from django.contrib.sites.models import Site

class Homepage(Site):
    subtitle = models.CharField(max_length=255,...)
    logo = models.ImageField()
    theme = models.ForeignKey(Theme, default=1, on_delete=models.SET_DEFAULT)

When using that in a UnicornView:

# components/master_data.py
from ..models import Homepage

class MasterDataView(UnicornView):
    homepage: Homepage = None

    def save(self):
        self.homepage.save()

and try to get that into HTML:

<!-- master_data.html -->
  <div>
    <input unicorn:model.defer="homepage.name" type="text" />
    {{ homepage.name }}
    <input unicorn:model.defer="homepage.subtitle" type="text" />
    {{ homepage.subtitle }}
    <button u:prevent unicorn:click="save()">Save</button>
  </div>

I don't get the homepage.name value - which should be inherited from Site. If I look at the js data Unicorn transfers:

<script type="application/json" id="unicorn:data:4DTnYCxq">{"id":"4DTnYCxq","name":"homepage.master_data","key":"","data":{"homepage":{"subtitle":"A subtitle!!","logo":"","theme":1,"pk":3},"view_is_async":false},"calls":[],"hash":"aTPpLzxk"}</script>

I think this should not be the case, as I would expect that Site.domain and Site.name is serialized too.

@adamghill
Copy link
Owner

Thanks for making this issue, I'll take a look!

@adamghill adamghill self-assigned this Nov 2, 2022
@adamghill
Copy link
Owner

I use serializers.serializer for Django models so this is why it's happening. I just am not sure what I am going to do to get around the limitation. I have a few ideas, but nothing solid, yet.

@adamghill
Copy link
Owner

#468 has been merged into main and is included in the new 0.49.0 version. Closing this for now, but let me know if you run into any issues with this going forward.

will9288 added a commit to will9288/django-unicorn that referenced this issue May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants