'Field value not persisted after import

Model.py

class Order(models.Model):
    customerID =  models.CharField(max_length=300, blank=True, null=True)
    osm_bol = models.CharField(max_length=300, blank=True, null=True)
    .....
    .....
    def __str__(self):
        return self.customerID 

Resouces.py

class NewOrders(resources.ModelResource):
    osm_bol = Field(attribute='osm_bol', column_name='Client Track ID')
    class Meta:
        model = Order
        fields = ('osm_bol')

Exel Sheet Column This is the Column that i want to import in my model

Problem the problem is i have the column name "Client Track ID" but in my model the name of attribute is "osm_bol" for the same field. when i import the file it shows nothing in "osm_bol" field. i mean its shows empty field. how can i fix it?



Solution 1:[1]

It looks like everything is defined correctly except for your fields declaration. Try to add a comma to turn it into a valid tuple:

fields = ('osm_bol',)

Some other things to try:

  • Use the Admin interface if you are not doing so already - this may give an message about any other errors - make sure you are importing the correct format (e.g. 'xlsx')
  • Step through with a debugger (this is the fastest way to spot the error). If you cannot do this, then add print statements
  • Double-check your imports: is Field imported from import_export?
  • Use the example application - and work from there to understand why your implementation is not working.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1