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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:26:45+00:00 2026-05-14T06:26:45+00:00

This is somewhat related to the question posed in this question but I’m trying

  • 0

This is somewhat related to the question posed in this question but I’m trying to do this with an abstract base class.

For the purposes of this example lets use these models:

class Comic(models.Model):
    name = models.CharField(max_length=20)
    desc = models.CharField(max_length=100)
    volume = models.IntegerField()
    ... <50 other things that make up a Comic>

    class Meta:
        abstract = True

class InkedComic(Comic):
    lines = models.IntegerField()

class ColoredComic(Comic):
    colored = models.BooleanField(default=False)

In the view lets say we get a reference to an InkedComic id since the tracer, err I mean, inker is done drawing the lines and it’s time to add color. Once the view has added all the color we want to save a ColoredComic to the db.

Obviously we could do

inked = InkedComic.object.get(pk=ink_id)
colored = ColoredComic()
colored.name = inked.name
etc, etc.

But really it’d be nice to do:

colored = ColoredComic(inked_comic=inked)
colored.colored = True
colored.save()

I tried to do

class ColoredComic(Comic):
    colored = models.BooleanField(default=False)

    def __init__(self, inked_comic = False, *args, **kwargs):
        super(ColoredComic, self).__init__(*args, **kwargs)
        if inked_comic:
            self.__dict__.update(inked_comic.__dict__)
            self.__dict__.update({'id': None}) # Remove pk field value

but it turns out the ColoredComic.objects.get(pk=1) call sticks the pk into the inked_comic keyword, which is obviously not intended. (and actually results in a int does not have a dict exception)

My brain is fried at this point, am I missing something obvious, or is there a better way to do this?

  • 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-14T06:26:45+00:00Added an answer on May 14, 2026 at 6:26 am

    What about a static method on the class to handle this?

    colored = ColoredComic.create_from_Inked(pk=ink_id)
    colored.colored = True
    colored.save()
    

    Untested, but something to this effect (using your code from above)

    class ColoredComic(Comic):
        colored = models.BooleanField(default=False)
    
        @staticmethod
        def create_from_Inked(**kwargs):
            inked = InkedComic.objects.get(**kwargs)
            if inked:
                colored = ColoredComic.objects.create()
                colored.__dict__.update(inked.__dict__)
                colored.__dict__.update({'id': None}) # Remove pk field value
                return colored
            else:
                # or throw an exception...
                return None
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is somewhat asp.net MVC related only for example purposes but I was hoping
[This question is somewhat related to this question , but the answers are not...]
This is somewhat related to another question I've asked but I figure why not
I think this is somewhat related to this question , but being not sure
(In Python 3.1) (Somewhat related to another question I asked , but this question
Although somewhat related to this question , I have what I think is a
I know this is somewhat of a server question, but I wanted to ask
This is somewhat related to another question that I've asked that I've pretty much
This is somewhat related to this question . Let's say I have a package
This is somewhat related to this question : I have a table with a

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.