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 675583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:50:02+00:00 2026-05-14T00:50:02+00:00

I want to do encode the data before saving it to a database table

  • 0

I want to do encode the data before saving it to a database table and decode it after reading it from the database table. I wanted to override django get and save methods.

something like:

class UserData(models.Model):
    userid = models.IntegerFields
    data = models.charField(max_length=25)

    def save(self, *args, **kwargs):
        encode_data(self.data)
        super(UserData, self).save(*args, **kwargs)

    def get(self, *args, **kwargs):
        data = super(UserData, self).get(*args, **kwargs)
        return decode_data(data)

django models have save method and I am able to override it and do what i want. But, they doesnt seem to have a get method which I can override.
How can I achieve this?
I want the data to be decoded on calling UserData.objects.all() or UserData.objects.get() or UserData.objects.filter() or any other such methods available

  • 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-14T00:50:02+00:00Added an answer on May 14, 2026 at 12:50 am

    Usually, you do this by overriding __init__. But since __init__ on Django Models does all kind of funky business, it’s not recommended to override it. Instead, listen for the post_init signal and do your decoding there:

    def my_decoder(instance, **kwargs):
        instance.decoded_stuff = decode_this(instance.encoded.stuff)
    
    models.signals.post_init.connect(my_decoder, UserData)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to encode data before storing it to my database. try {
I want to encode and decode Bitmap object in string base64 . I use
I want to base64 encode data to put it in a URL and then
I am using Snappy-java to encode JSON data and I want to store the
I have a PHP data structure I want to JSON encode. It can contain
I want to return JSON data from a resulted SQL statement in a PHP
I want to encode DNS protocol header using C and create a UDP datagram.
I want to encode binary file into base64 and put it into php page
As the title mentioned, I want to encode a Image Obj into some kind
In my java app I'm preventing XSS attacks. I want to encode URL and

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.