Django - No column found for custom field?

Stack Overflow Asked by jare42 on July 29, 2020

I’m having an issue creating a custom field for a user in Django currently. Ideally, I would want to create a custom field for a "CustomProgressBar" class that updates depending on the parameter "donations" passed into it and should be different for each user. Whenever I try to access an account on the server it returns "django.db.utils.OperationalError: table donorportal_profile has no column named progress". I have tried multiple times to makemigrations, migrate, and syncdb. I think there is an issue where I am not converting it to/from the database a certain way. I’m also unsure what to put in the parameters when I create the field in the model class. Any code relevant to my issue is attached below. I’m new to Django, so thank you for any help you can provide me!

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    city = models.CharField(max_length=40, default='')
    state = models.CharField(max_length=2, default='')
    website = models.URLField(default='')
    phone = models.IntegerField(default=0)
    progress = user_assets.ProgressField()
class CustomProgressBar:
    def __init__(self, donations): = donations
        if 0 <= donations < 25:
            self.tier = 0
            self.percent = donations / 25
        elif 25 <= donations < 250:
            self.tier = 1
            self.percent = donations / 250
        elif 250 <= donations < 2500:
            self.tier = 2
            self.percent = donations / 2500
        elif donations >= 2500:
            self.tier = 3
            self.percent = 100
            self.tier = 0
            self.percent = 0
def parse_progress_bar(progress_bar_string):
    return CustomProgressBar(progress_bar_string)
class ProgressField(models.Field):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def deconstruct(self):
        name, path, args, kwargs = super().deconstruct()
        return name, path, args, kwargs

    def from_db_value(self, value, expression, connection):
        if value is None:
            return value
        return parse_progress_bar(value)

    def to_python(self, value):
        if isinstance(value, CustomProgressBar):
            return value

        if value is None:
            return value

        return parse_progress_bar(value)

    def get_prep_value(self, value):
        return value

Add your own answers!

Related Questions

Trying to get property ‘post_title’ of non-object with

1  Asked on January 1, 2022 by german-mazzaferro


Select max for a tuple in table

2  Asked on January 1, 2022 by maxsteel


bind python/flask module app yo WINDOWS Server IIS

1  Asked on January 1, 2022 by shaul-sondak


Break apart email attachment if zip is too big to email

0  Asked on January 1, 2022 by programmingislife


Retrieve previous position of an Image on refresh page

2  Asked on January 1, 2022 by roel-thijssen


EMP id Masking with asterisk inbetween string

2  Asked on December 30, 2021 by bala


Create Sidebar Nav menu

1  Asked on December 30, 2021


Avoid select from dual Union in PL/SQL

3  Asked on December 30, 2021 by alc


SQL pulling distinct values and creating an ID

2  Asked on December 30, 2021 by jamheadart


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir