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

The Archive Base Latest Questions

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

I have a model with a custom property class RecipeIngredient(models.Model): recipe = models.ForeignKey(Recipe) ingredient

  • 0

I have a model with a custom property

class RecipeIngredient(models.Model):
    recipe = models.ForeignKey(Recipe)
    ingredient = models.ForeignKey(Ingredient)
    serving_size = models.ForeignKey(ServingSize)
    quantity = models.IntegerField()
    order = models.IntegerField()
    created = models.DateTimeField(auto_now_add = True)
    updated = models.DateTimeField(auto_now = True)

    def _get_json_data(self):
        return u'%s %s' % (self.id, self.ingredient.name)

    json_data = property(_get_json_data)

I am trying to display the property ‘json_data’ in my template.

I have this piece of code in my form

class RecipeIngredientForm(forms.ModelForm):
      json_data = forms.CharField(widget=forms.HiddenInput())

      def __init__(self, *args, **kwargs):
            super(RecipeIngredientForm, self).__init__(*args, **kwargs)
            print('here')
            if kwargs.has_key('instance'):
                instance = kwargs['instance']
                print(instance)
                self.initial['json_data'] = instance.json_data

I know the data in my property ‘json_data’ is not valid, but I am unable to see the data from this property in my template.

In my views, I have this piece of code

RecipeIngredientFormSet = inlineformset_factory(models.Recipe, models.RecipeIngredient, form=forms.RecipeIngredientForm, extra=0)

recipe_id = int(id)

objRecipe = models.Recipe.objects.get(id=recipe_id)
recipe = forms.RecipeForm(instance=objRecipe)

recipeIngredients = RecipeIngredientFormSet(instance = objRecipe)

I guess my question is how do I display data from an extra model field?

  • 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-16T09:08:54+00:00Added an answer on May 16, 2026 at 9:08 am

    pass the data of the extra fields as initial data to the form

    initial_data = [{'json_data': objRecipe.json_data}]
    recipeIngredients = RecipeIngredientFormSet(initial=initial_data, instance = objRecipe)
    

    for correct usage of initial data refer using initial data with formset

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DUPLICATE: Using a Django custom model method property in order_by() I have two models;
I have a property on my view model that is a custom class with
I have a model class that uses a custom validator as shown in following
I have a custom class Spieltag containing a property SpieltagDaten (custom class). SPieltagDaten has
If I have in my model class a property of type DateTime how can
I have created a custom attribute 'RoleAction' and added to the model property public
I have a custom property on my Django model that returns the full name
C#, MVC 2 RC 2... I have the following property on my model class:
I have a datagrid bound to a list of a custom model class. In
I have a model called UserProfile defined as class UserProfile(models.Model): user = models.OneToOneField(User, related_name='userprofile_from_user')

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.