Hi 赖信桃,

Sorry for formating problem. Here it is

class AbstractDataModel(models.Model):

    xxx


    class Meta:
        abstract = True


    def __iter__(self):

         return iter([self.xxx, self.yyy, self.zzz, self.aaa,
              self.qqq, self.mode_bbb])


class DataModel(AbstractDataModel):

    pass


class DataModelArchive(AbstractDataModel):
    # https://stackoverflow.com/questions/21699707/python-how-
to-copy-all-attibutes-from-base-class-to-derived-one
    def __init__(self, source=None):
        if source is not None:
            self.__dict__.update(source.__dict__)



2018-06-27 4:34 GMT+02:00 赖信桃 <[email protected]>:

> Can you format your code or post it on a gist?
> On Wed, Jun 27, 2018 at 00:17 <[email protected]> wrote:
>
>> Hi all :-)
>>
>> I'd like to archive some data.
>>
>> I did that :
>>
>> class AbstractDataModel(models.Model):
>>
>> xxx
>>
>>
>> class Meta:
>>         abstract = True
>>
>>
>> def __iter__(self):
>>
>>         return iter([self.xxx, self.yyy, self.zzz, self.aaa,
>>             self.qqq, self.mode_bbb])
>>
>>
>> class DataModel(AbstractDataModel):
>>
>>
>> pass
>>
>>
>> class DataModelArchive(AbstractDataModel):
>>     # https://stackoverflow.com/questions/21699707/python-how-
>> to-copy-all-attibutes-from-base-class-to-derived-one
>>     def __init__(self, source=None):
>>         if source is not None:
>>             self.__dict__.update(source.__dict__)
>>
>>
>>
>> But when I want to access data in DataModelArchive, like
>> DataModelArchive.objects.all() for example,
>> I get
>>
>>
>> Traceback (most recent call last):
>>   File "/home/.../tests.py", line 1090, in test_archive
>>     print(DataModelArchive.objects.all())
>>   File "/home/.../venv/lib/python3.6/site-packages/django/db/
>> models/query.py", line 248, in __repr__
>>     data = list(self[:REPR_OUTPUT_SIZE + 1])
>>   File "/home/.../venv/lib/python3.6/site-packages/django/db/
>> models/query.py", line 272, in __iter__
>>     self._fetch_all()
>>   File "/home/.../venv/lib/python3.6/site-packages/django/db/
>> models/query.py", line 1179, in _fetch_all
>>     self._result_cache = list(self._iterable_class(self))
>>   File "/home/.../venv/lib/python3.6/site-packages/django/db/
>> models/query.py", line 63, in __iter__
>>     obj = model_cls.from_db(db, init_list, row[model_fields_start:model_
>> fields_end])
>>   File "/home/.../lib/python3.6/site-packages/django/db/models/base.py",
>> line 507, in from_db
>>     new = cls(*values)
>> TypeError: __init__() takes from 1 to 2 positional arguments but 11 were
>> given
>>
>>
>>
>> What am I doing wrong ?
>>
>> Thx
>> ;-)
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> 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/ac3a7a8f-f878-48b3-943a-eb47f6b03e7e%
>> 40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/ac3a7a8f-f878-48b3-943a-eb47f6b03e7e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/django-users/gHKY0BAcTi4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> 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/CAMv51WTXNjz1Px76v5_7P%2BMmUnbHH8Yw%2BdwJPR%
> 2BX7ccorHPZBA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMv51WTXNjz1Px76v5_7P%2BMmUnbHH8Yw%2BdwJPR%2BX7ccorHPZBA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CAPLHwtx5_z8B47oVsodDNnp9hy%3DbjSK5GsmT%3DZ1k%3DZp2kgNDtQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to