class EvalState(models.Model,AtlasBaseHelper):
    """
    Represents Eval State:
    ACTIVE
    INACTIVE
    DELETE
    NA
    """
    name = models.CharField(max_length=32, unique=True)
    friendly_name = models.CharField(max_length=32, unique=True)
    description = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        verbose_name = "Eval States"

    def __unicode__(self):
        return self.name

class Bundle(AtlasAuditModel, AtlasBaseHelper):^M
    """^M
    Represents the bundle purchased by the customer. The bundle^M
    contains a reference identifier which remains the same if the^M
    the bundle is either upgraded or entended.^M
    A bundle can have 0 or more features.^M
    """^M
    bundle_id = models.CharField(verbose_name="Bundle ID",^M
                                 max_length=32,^M
                                 unique=True)^M
    customer = models.ForeignKey(Customer)^M
    description = models.CharField(max_length=255, blank=True, null=True)^M
    state = models.ForeignKey(BundleState)^M
    extended_state = models.ForeignKey(BundleExtendedState)^M
    type = models.ForeignKey(BundleType)^M
    quantity = models.FloatField(blank=False)^M
    start_date = models.DateField(verbose_name="Start Date")^M
    end_date = models.DateField(verbose_name="End Date")^M
    stage = models.CharField(max_length=32, blank=True, null=True)^M
    *stage_state = models.ForeignKey(EvalState, verbose_name="Eval State", 
null=True)*

The Below is the Migration Script written to add the States in to EvalState:
def forwards(apps, schema_editor):
    DcPropertyType = apps.get_model("atlas", "evalstate")
    db_alias = schema_editor.connection.alias

    DcPropertyType.objects.using(db_alias).bulk_create([
        DcPropertyType(name="ACTIVE", friendly_name="EVAL Active", 
description="Bundle EVAL State is ACTIVE"),
        DcPropertyType(name="INACTIVE", friendly_name="EVAL 
InActive",description="Bundle EVAL state is INACTIVE"),
        DcPropertyType(name="DELETE", friendly_name="EVAL Delete", 
description="Bundle EVAL state is DELETE"),
        DcPropertyType(name="NA", friendly_name="EVAL NotApplicable", 
description="Bundle EVAL state is not applicable")
    ])

def backwards(apps, schema_editor):
    DcPropertyType = apps.get_model("atlas", "evalstate")
    db_alias = schema_editor.connection.alias

    DcPropertyType.objects.using(db_alias).filter(name="ACTIVE", 
description="Bundle EVAL State is ACTIVE").delete()
    DcPropertyType.objects.using(db_alias).filter(name="INACTIVE", 
description="Bundle EVAL state is INACTIVE").delete()
    DcPropertyType.objects.using(db_alias).filter(name="DELETE", 
description="Bundle EVAL state is DELETE").delete()
    DcPropertyType.objects.using(db_alias).filter(name="NA", 
description="Bundle EVAL state is not applicable").delete()


class Migration(migrations.Migration):

    dependencies = [
        ('atlas', '0012_add_eval_states'),
    ]

    operations = [
        migrations.RunPython(forwards, backwards),
    ]

Does this make sense for the model structure. I do not have any Models 
Diagram for the same. 

---
Arun

On Monday, August 7, 2017 at 4:13:33 PM UTC+5:30, lemme smash wrote:
>
> you didn't show me a model structure, you just showed another model, so I 
> can't give you example without picture of what's going on there
>
> On Monday, August 7, 2017 at 1:39:49 PM UTC+3, Arun S wrote:
>>
>> Can you just give an Example for this taking a Query.
>>
>>
>>
>> On Monday, August 7, 2017 at 3:37:04 PM UTC+5:30, lemme smash wrote:
>>>
>>> i meant EvalState model
>>> if name attribute on it is a ForeignKey you should get corresponding 
>>> queryset of model it links to
>>> if it's charfield, you should use text choices 
>>>
>>> On Monday, August 7, 2017 at 6:22:50 AM UTC+3, Arun S wrote:
>>>>
>>>> The Models Look like this :
>>>>
>>>> stage_state = models.ForeignKey(EvalState, verbose_name="Eval State")
>>>> class Bundle(AtlasAuditModel, AtlasBaseHelper):^M
>>>>     """^M
>>>>     Represents the bundle purchased by the customer. The bundle^M
>>>>     contains a reference identifier which remains the same if the^M
>>>>     the bundle is either upgraded or entended.^M
>>>>     A bundle can have 0 or more features.^M
>>>>     """^M
>>>>     bundle_id = models.CharField(verbose_name="Bundle ID",^M
>>>>                                  max_length=32,^M
>>>>                                  unique=True)^M
>>>> ....
>>>> ....
>>>> ....
>>>>     stage_state = models.ForeignKey(*EvalState*, verbose_name="Eval 
>>>> State")
>>>>
>>>>
>>>> atlas_bundle;
>>>> atlas_bundle | CREATE TABLE `atlas_bundle` (
>>>>   `id` int(11) NOT NULL AUTO_INCREMENT,
>>>>  ...
>>>> ....
>>>> ...
>>>>   *`stage_state_id` int(11) NOT NULL,*
>>>>   PRIMARY KEY (`id`),
>>>>   *KEY `atlas_bundle_36c1765e` (`stage_state_id`)*
>>>> ) ENGINE=InnoDB AUTO_INCREMENT=1408 DEFAULT CHARSET=latin1 
>>>> ROW_FORMAT=DYNAMIC |
>>>> 19 rows in set (0.01 sec)
>>>>
>>>> desc *evalstate*;
>>>> +---------------+--------------+------+-----+---------+----------------+
>>>> | Field         | Type         | Null | Key | Default | Extra          |
>>>> +---------------+--------------+------+-----+---------+----------------+
>>>> | id            | int(11)      | NO   | PRI | NULL    | auto_increment |
>>>> | name          | varchar(32)  | NO   | UNI | NULL    |                |
>>>> | friendly_name | varchar(32)  | NO   | UNI | NULL    |                |
>>>> | description   | varchar(255) | YES  |     | NULL    |                |
>>>> +---------------+--------------+------+-----+---------+----------------+
>>>> 4 rows in set (0.00 sec)
>>>>
>>>> Whats the Difference in having qs when there is a foriegn Key value? 
>>>>
>>>> Arun
>>>>
>>>> On Sunday, August 6, 2017 at 7:48:11 PM UTC+5:30, lemme smash wrote:
>>>>>
>>>>> so, you can maybe show you models structure here?
>>>>> also, if it is a ForeignKey, why you trying to filter qs by string 
>>>>> values? I mean Q(name = 'ACTIVE')
>>>>> it's shouldn't work
>>>>>
>>>>>
>>>>> On Sunday, August 6, 2017 at 5:22:21 AM UTC+3, Arun S wrote:
>>>>>>
>>>>>> Yes, name is a foreign key here.
>>>>>
>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55f324bc-3566-4f4d-8b20-19f2c0bd53e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to