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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:11:35+00:00 2026-06-06T13:11:35+00:00

I have a ActionAdmin model, which is used as ActionAdminInline in the InvoiceAdmin model.

  • 0

I have a ActionAdmin model, which is used as ActionAdminInline in the InvoiceAdmin model.

In InvoiceModel i override save_formset, to auto set some values. Setting the values for each Action instance is no problem, but i could not get the fields of the parent Invoice.

I thought it had to be self or self.project.pk
I also tried to get it by form.project.pk seen in some other thread.

The errors i get, are about no such Field in InvoiceAdmin. That makes sense to me, self is an InvoiceAdmin object and not an Invoice object. I think i had to get the Invoice object fields to set Action instance.invoice and instance.project.

Does somebody know, how to get this parent object values ???

looks like this:

class ActionAdmin(admin.ModelAdmin):
...


class ActionInlineForm(ModelForm):
    class Meta:
        model = Action
        fields = ['name','tax', 'price','duration_extern',]


class ActionInline(admin.TabularInline):
    model = Action
    form = ActionInlineForm
    extra = 0
    ordering = ('date_finished',)
    can_delete=False
    readonly_fields = ['non_editable_date_finished','non_editable_duration','get_remove_invoice_pos_link']




class InvoiceAdmin(admin.ModelAdmin):
...
...
...
  inlines = [ActionInline,]
  ...
  ...
  ...
  def save_formset(self, request, form, formset, change):
      instances = formset.save(commit=False)
      for instance in instances:
          usr = User.objects.get(id=7)
          try:
            instance.created_by = instance.created_by
          except:
            instance.created_by = usr

          try:
            instance.owner = instance.owner
          except:
            instance.owner = usr

          instance.modified_by = usr

          try:
            instance.date_created = instance.date_created
          except:
            instance.date_created = date.today

          instance.date_modified = date.today:

          ### MAN, This WORKS NOW ###
          try:
              instance.project = instance.project
          except:
            pr = Project.objects.get(id=instance.invoice.project.id)
            instance.project = pr


          actstat = ActionStatus.objects.get(id=2)
          instance.actionstatus = actstat

          try:
            instance.actioncategory = instance.actioncategory
          except:
            cat = ActionCategory.objects.get(id=9)
            instance.actioncategory = cat

          instance.done = True
          instance.billed = True    
          instance.save()
      formset.save_m2m()

This is the error message:

AttributeError at /workflow/invoice/21/
    ...
    Exception Type:     AttributeError
    Exception Value:    'InvoiceAdmin' object has no attribute 'id'
    ...

Traceback
    form <django.forms.models.InvoiceForm object at 0x7f7f7421de10>
    instances [<Action: aaaaa>]
    self <workflow.admin.InvoiceAdmin object at 0x7f7f7421dad0>

Is it the problem, that the self object is InvoiveAdmin and not Invoice? I mean the instances objects are Action and not ActionAdmin?!

  • 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-06-06T13:11:36+00:00Added an answer on June 6, 2026 at 1:11 pm

    OK. i found a solution for instance.invoice. It’s correctly set without doing anything for instance.invoice. I removed the line “instance.invoice = self” from the code above.

    The solution to get the project by parent object, which is an invoice is done by “instance.invoice.project.id”

    So i traverse form action to invoice to project an than to it’s id. Changed this also above.

    And it’s nescessary to check instance fields with try,except. First i tried
    if not instance.project
    and
    if not hasatrr(instance,’project’)
    or
    if instance.project=””
    But without exception handling it raises an DoesNotExists error. Changed it from if/else to try/except above.


    BTW

    Realy rare. I’m just changing something in ActionAdmin save_model

    When i try to proove instance field there, the same way with try/except like in save_formset, i don’t works.

    In save_model i had to do:

     if not instance.price:
            instance.price = instance.project.customer.price
    

    this fails

      try:
          instance.price = instance.price
      except:
          instance.price = instance.project.customer.price
    

    And in save_formset it’s viceversa ??? !

    Somebody could explain that to me?

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

Sidebar

Related Questions

I've set up ActiveAdmin early in my project and used the default admin_users model
I'm using active admin for my rails app. I have a customer model which
I have a model, Domain , which has a text field, names . >
I have a resource Photos, which belongs to Adverts. In ActiveAdmin, users should be
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
I have an ActiveAdmin app with a simple model that I want to persist
I have a rails app that is using Devise, with a User model, no
I have a form with a field that may have zero to multiple values

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.