Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 537099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:53:28+00:00 2026-05-13T09:53:28+00:00

I’m developing a web-app where the user can create multiple related elements and then

  • 0

I’m developing a web-app where the user can create multiple related elements and then save those elements to a database. The webapp has no idea of what the primary keys will be in the database so it assigns each element a UUID. These UUIDs are saved with each element in the database. When the webapp sends the data to the webserver to be placed in the database it encodes everything using JSON. The JSON is then deserialized by the webserver using serializers.deserialize('json', DATA). However, some of the models have foreign keys, which are sent in the JSON payload as references to the UUIDs of the associated elements rather than the database ids. For example, we may have a simple link object:

class Link(models.Model):
    uuid = models.CharField(max_length=32)
    source = models.ForeignKey(Node, related_name='source')
    target = models.ForeignKey(Node, related_name='target')

If the source had an id value of 2 and the target had an id value of 12, this would be serialized to JSON as this:

{"uuid": "[some long uuid]",
 "source": 2,
 "target": 12}

However, because in this case we don’t know the database ids of source and target, probably because they haven’t been set yet, the best I can do is pass in the UUID’s like this:

{"uuid": "[some long uuid]", 
 "sourceuuid": "[uuid of source]", 
 "targetuuid": "[uuid of target]"}

Unfortunately, this raises an exception of FieldDoesNotExist: Link has no field named u'sourceuuid' when I call serializers.deserialize on the data.

I’d like to find a way that I can pass the UUID’s in and then have the database fill in the id’s once it’s saved the appropriate parts or look them up where necessary. I don’t want to save sourceuuid and targetuuid in the database as it’s a lot less space to save an integer and the indicies should be faster too.

So, what I’m looking for is a temporary field. One that I can instantiate and reference, but that is never saved back to the database. Any ideas on how I would create such a thing?

UPDATE with more clarification

Thanks for the help so far, I’m aware that they’re Python objects and I can assign arbitrary fields to the objects. However, the problem is that serializers.deserialize('json', INDATA) throws errors.

For reference here’s a hunk of JSON that the deserializer likes, it has the foreign keys with their IDs:

ser='''[{"pk": 1, "model": "myapp.link", 
         "fields": {"uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
                    "source": 2,
                    "target": 12}}]'''
serializer.deserialize('json',ser)

However, what I can provide is this:

ser='''[{"pk": 1, "model": "myapp.link",
         "fields": {"uuid": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
                    "sourceuuid": "11111111-2222-3333-4444-555555555555",
                    "targetuuid": "66666666-7777-8888-9999-000000000000"}}]'''
serializer.deserialize('json',ser)
FieldDoesNotExist: Link has no field named u'sourceuuid'

The reason I need to dummy field to be an actual field is because the deserialize requires actual fields.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:53:28+00:00Added an answer on May 13, 2026 at 9:53 am

    You can define a foreign key to non-materialized django model which stores the info you require.

    To do so, in the new model to which foreign key (or a OnetoOne Key) is defined, just place

    class _meta:
        managed = False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.