python - Django Import/Export to multiple Models (foreignkey) -


this has been asked several times- none of solutions worked me.

the code below works (in there no errors) not see import new data foreign key class. import data if already exists in foreign key.

does make sense?

models.py (snippet)

... class store(models.model):      store_name = models.charfield(max_length=30)     def __unicode__(self):         return self.store_name     #etc  class product(models.model):      store = models.foreignkey(store)     category = models.foreignkey(category)     first_name = models.charfield(max_length=30)     second_name = models.charfield(max_length=30) ... 

admin.py

admin.site.register(category) admin.site.register(store)  class productresource(resources.modelresource):       store_name = fields.field(column_name='store_name', attribute='store',                        widget=foreignkeywidget(store, 'store_name'))      def __unicode__(self):         return self.store_name.name      class meta:         model = product         fields = ('id', 'first_name', 'second_name','store_name')         export_order = ('id', 'second_name', 'first_name')         skip_unchanged = false         report_skipped = false         widgets = {                 'published': {'format': '%d.%m.%y'},                 }   class productadmin(importexportmodeladmin):     resource_class = productresource     list_display = ('first_name', 'second_name')  admin.site.register(product, productadmin) 

try

 store_name = fields.field(column_name='store_name', attribute='store',                            widget=foreignkeywidget(store, 'store_name')) 

i suggest name model field uncapitalized

it's hard understand asking.

if saying "want create foreign key objects , fill foreign object's attribute excel data"

i think need first create foreign object , relate other model means, need override or define function in modelresource class , have called admin.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -