Newbie : Help for using RequestContext

2018-01-09 Thread Mickael . barbo
Hello to all Django users :-)

I'm new to Django and this is my first post.

I'd like to implement breadcrumbs on all my pages.

My strategy is to create a middleware and to use RequestContext to
add a dict to the context of each request then use the context in my html

My problem is that I don't understand how to link RequestContext to 
my request. Hereafter my code :

my_middleware.py
from django.template import RequestContext


class SimpleBreadcrumbs(object):
def __init__(self, get_response):
self.get_response = get_response
# One-time configuration and initialization.


def __call__(self, request):
# Code to be executed for each request before
# the view (and later middleware) are called.

request_context = RequestContext(request)
request_context.push({"level0": "Adrian", "level1": "Thomas"})

response = self.get_response(request)


# Code to be executed for each request/response after
# the view is called.

return response


my_template.html

{% extends 'pricing/body.html' %}

{% block content %}

{{ level0 }}

{% endblock content %}


What I'm doing wrong ?

Thx for your help

Micka
Django newbie
;-)





-- 
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/6cf0e65a-2b48-4bbb-a8a7-0351252e49f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie : Help for using RequestContext

2018-01-10 Thread mickael . barbo
Oh, 
*Thank you Andréas for your kind attention and your reactivity.*
Nice, I didn't know about request.session... And thanks to you, *now I Know* 
:-)

Just for archive, I found a way with context_processors here (old django 
version, but I adapt to django 2) :
http://apprendre-python.com/page-django-context-processor-template

Very happy to join Django community :D

Micka

Le mercredi 10 janvier 2018 09:36:46 UTC+1, Andréas Kühne a écrit :
>
> Hi Micka,
>
> And welcome to django.
>
> Regarding how to add things in middleware - you can add the information to 
> the session like this:
>
> class SimpleBreadcrumbs(object):
> def __init__(self, get_response):
> self.get_response = get_response
> # One-time configuration and initialization.
>
>
> def __call__(self, request):
> # Code to be executed for each request before
> # the view (and later middleware) are called.
>
> request.session['breadcrumbs'] = {"level0": "Adrian", "level1": 
> "Thomas"}
>
> response = self.get_response(request)
>
>
> # Code to be executed for each request/response after
> # the view is called.
>
> return response
>
>
> Then in your templates you can do this:
>
> {% extends 'pricing/body.html' %}
>
> {% block content %}
>
> {{ breadcrumbs.level0 }} / {{ breadcrumbs.level1 }}
>
> {% endblock content %}
>
> Regards,
>
> Andréas
>
> 2018-01-10 0:42 GMT+01:00 >:
>
>> Hello to all Django users :-)
>>
>> I'm new to Django and this is my first post.
>>
>> I'd like to implement breadcrumbs on all my pages.
>>
>> My strategy is to create a middleware and to use RequestContext to
>> add a dict to the context of each request then use the context in my html
>>
>> My problem is that I don't understand how to link RequestContext to 
>> my request. Hereafter my code :
>>
>> my_middleware.py
>> from django.template import RequestContext
>>
>>
>> class SimpleBreadcrumbs(object):
>> def __init__(self, get_response):
>> self.get_response = get_response
>> # One-time configuration and initialization.
>>
>>
>> def __call__(self, request):
>> # Code to be executed for each request before
>> # the view (and later middleware) are called.
>>
>> request_context = RequestContext(request)
>> request_context.push({"level0": "Adrian", "level1": "Thomas"})
>>
>> response = self.get_response(request)
>>
>>
>> # Code to be executed for each request/response after
>> # the view is called.
>>
>> return response
>>
>>
>> my_template.html
>>
>> {% extends 'pricing/body.html' %}
>>
>> {% block content %}
>>
>> {{ level0 }}
>>
>> {% endblock content %}
>>
>>
>> What I'm doing wrong ?
>>
>> Thx for your help
>>
>> Micka
>> Django newbie
>> ;-)
>>
>>
>>
>>
>>
>> -- 
>> 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...@googlegroups.com .
>> To post to this group, send email to django...@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/6cf0e65a-2b48-4bbb-a8a7-0351252e49f9%40googlegroups.com
>>  
>> 
>> .
>> 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 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/e6de4d19-7778-4988-abbf-3906a134bc42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Newbie : Best data archive strategy

2018-06-12 Thread mickael . barbo
Hi,

I'd like to archive some data.

I came with this idea :


class DataModel(models.Model):
xxx

class DataModelArchive(DataModel):
pass


The DataModelArchive database created has only "a pointer" to DataModel.

I saw a post indicating that I'll have to first create an AbstractDataModel 
and inherit for it for both DataModelArchive and DataModel.

Well, what is the "best way" to archive data using Django ?

Thx for your attention

Micka

-- 
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/ef59e00a-3354-44f5-9c99-5ca85885026e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie : Best data archive strategy

2018-06-12 Thread mickael . barbo
Thanks Matthew for your response.

I looked at Reversion. If I understand correctly what it did, it duplicate 
each transaction on internal database ?

Le mardi 12 juin 2018 20:01:02 UTC+2, Matthew Pava a écrit :
>
> I think what you’re really looking for is an audit log.  There are some 
> Django packages available that do that automatically.
>
>  
>
> You might find this one quite helpful, called Django Reversion:
>
> https://github.com/etianen/django-reversion
>
>  
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *
> mickae...@gmail.com 
> *Sent:* Tuesday, June 12, 2018 12:22 PM
> *To:* Django users
> *Subject:* Newbie : Best data archive strategy
>
>  
>
> Hi,
>
> I'd like to archive some data.
>
> I came with this idea :
>
>
> class DataModel(models.Model):
>
> xxx
>
>
> class DataModelArchive(DataModel):
>
> pass
>
>  
>
>
> The DataModelArchive database created has only "a pointer" to DataModel.
>
> I saw a post indicating that I'll have to first create an 
> AbstractDataModel and inherit for it for both DataModelArchive and 
> DataModel.
>
> Well, what is the "best way" to archive data using Django ?
>
> Thx for your attention
>
> Micka
>
> -- 
> 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...@googlegroups.com .
> To post to this group, send email to djang...@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/ef59e00a-3354-44f5-9c99-5ca85885026e%40googlegroups.com
>  
> 
> .
> 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 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/86e18583-0376-43f2-8419-b557459b5ca7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie : Best data archive strategy

2018-06-12 Thread Mickael Barbo
Ok, so "audit log" is like a "snapshot". I think it's too much for what I
need.

To clarify my needs, I have a data that once "used/read", it's no more
needed.
I just want to keep it "archived", in an other place to get access to it if
I want to add some function (statistics, etc...).

So, Gerardo, it seems to be like " I want to "move" data to an archive
system (data is still relevant and useful)."

Hope this clarify my needs...

Thx Matthew and Gerardo for your help.


2018-06-12 20:38 GMT+02:00 Gerardo Palazuelos Guerrero <
gerardo.palazue...@gmail.com>:

> Hi Mickael,
> When I read Archive, in my mind is a different thing, not the same as
> audit. So, for one moment, think about situation/scenario you are working
> on.
>
> Archive is to manage data purge from my transactional tables; this means I
> want to "delete" data (that has not more value) or I want to "move" data to
> an archive system (data is still relevant and useful).
>
> Audit is to create a perfect tracking of transitions on value overtime.
> This is required due to special regulations you have.
>
> So, it might be useful if you clarify what is the scenario you are trying
> to solve.
>
> Regards,
> Gerardo.
>
>
>
> --
> Gerardo Palazuelos Guerrero
>
>
> On Tue, Jun 12, 2018 at 12:14 PM, Matthew Pava 
> wrote:
>
>> Hi Mickael,
>>
>> It saves a copy of each record every time a record is changed.  But it is
>> saved in a separate table, so it doesn’t change your model’s table.
>>
>>
>>
>> *From:* django-users@googlegroups.com [mailto:django-users@googlegro
>> ups.com] *On Behalf Of *mickael.ba...@gmail.com
>> *Sent:* Tuesday, June 12, 2018 1:17 PM
>> *To:* Django users
>> *Subject:* Re: Newbie : Best data archive strategy
>>
>>
>>
>> Thanks Matthew for your response.
>>
>> I looked at Reversion. If I understand correctly what it did, it
>> duplicate each transaction on internal database ?
>>
>> Le mardi 12 juin 2018 20:01:02 UTC+2, Matthew Pava a écrit :
>>
>> I think what you’re really looking for is an audit log.  There are some
>> Django packages available that do that automatically.
>>
>>
>>
>> You might find this one quite helpful, called Django Reversion:
>>
>> https://github.com/etianen/django-reversion
>>
>>
>>
>>
>>
>> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On
>> Behalf Of *mickae...@gmail.com
>> *Sent:* Tuesday, June 12, 2018 12:22 PM
>> *To:* Django users
>> *Subject:* Newbie : Best data archive strategy
>>
>>
>>
>> Hi,
>>
>> I'd like to archive some data.
>>
>> I came with this idea :
>>
>>
>> class DataModel(models.Model):
>>
>> xxx
>>
>>
>> class DataModelArchive(DataModel):
>>
>> pass
>>
>>
>>
>>
>> The DataModelArchive database created has only "a pointer" to DataModel.
>>
>> I saw a post indicating that I'll have to first create an
>> AbstractDataModel and inherit for it for both DataModelArchive and
>> DataModel.
>>
>> Well, what is the "best way" to archive data using Django ?
>>
>> Thx for your attention
>>
>> Micka
>>
>> --
>> 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...@googlegroups.com.
>> To post to this group, send email to djang...@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/ms
>> gid/django-users/ef59e00a-3354-44f5-9c99-5ca85885026e%40googlegroups.com
>> 
>> .
>> 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 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/ms
>> gid/django-users/86e18583-0376-43f2-8419-b557459b5ca7%40googlegroups.com
>> 
>> .
>> 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 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/ms
>> gid/django-users/148f20f481e5409a833ea043f771cbda%40ISS1.ISS.LOCAL
>> 

Newbie : Implementation possible ?

2018-06-26 Thread mickael . barbo
Hi community :)

I'd like to implement something like "joined image".

In Database, I'd like CoreObject to have the key of "Object1" OR "Object2" 
OR "Object3" (like foreignKey).

How can I do that ?

The context is that CoreObject is a central DataBaseFile and will receive 
information from one of ObjectX + ObjectX.pk to access ObjectX.

Thanks for your help

Micka

-- 
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/99c9f8e1-f0be-428f-abca-8bc65a9666cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Newbie : Object copy - weird error :-)

2018-06-26 Thread mickael . barbo
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(DataModel):

pass


class DataModelArchive(DataModel):
# 
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 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/42c0ac75-5255-4573-95cc-097f8b61fe17%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Newbie : Object copy - weird error :-)

2018-06-26 Thread mickael . barbo
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 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/ac3a7a8f-f878-48b3-943a-eb47f6b03e7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie : Object copy - weird error :-)

2018-06-26 Thread mickael . barbo
Error typo, I creates a new thread with the good description ;-)

Le mardi 26 juin 2018 16:35:27 UTC+2, Nelson Varela a écrit :
>
> The following class is kinda weird:
> class DataModel(DataModel):
>
> A class which inherits itself???
>
>
>
> On Tuesday, June 26, 2018 at 11:31:24 AM UTC+2, mickae...@gmail.com 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(DataModel):
>>
>> pass
>>
>>
>> class DataModelArchive(DataModel):
>> # 
>> 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 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/d1051e67-7456-4263-937e-e7d0541334b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie : Object copy - weird error :-)

2018-06-29 Thread Mickael Barbo
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 赖信桃 :

> Can you format your code or post it on a gist?
> On Wed, Jun 27, 2018 at 00:17  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 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/ac3a7a8f-f878-48b3-943a-eb47f6b03e7e%
>> 40googlegroups.com
>> 
>> .
>> 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
> 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/CAMv51WTXNjz1Px76v5_7P%2BMmUnbHH8Yw%2BdwJPR%
> 2BX7ccorHPZBA%40mail.gmail.com
> 
> .
>
> 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 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/CAPLHwtx5_z8B47oVsodDNnp9hy%3DbjSK5GsmT%3DZ1k%3DZp2kgNDtQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Newbie : Object copy - weird error :-)

2018-06-29 Thread Mickael Barbo
Hello  Julio,

Ok, I see.

I try to create a way to archive (copy) the same object instance on an
other DataBase.

I followed this advice : # https://stackoverflow.com/
questions/21699707/python-how-to-copy-all-attibutes-from-
base-class-to-derived-one


2018-06-27 14:56 GMT+02:00 Julio Biason :

> Hi Mikael,
>
> The problem is happening because of this: __init__() takes from 1 to 2
> positional arguments but 11 were given
>
> On your new __init__(), you added just 2 parameters: `self` and `source`.
> But you overwrote the default `models.Model` init, which receives way more
> parameters (the original signature for this function is `__init__(self,
> *args, **kwargs)`).
>
> What are you actually trying to achieve with this?
>
> On Tue, Jun 26, 2018 at 1:17 PM,  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_f
>> ields_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 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/ms
>> gid/django-users/ac3a7a8f-f878-48b3-943a-eb47f6b03e7e%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Julio Biason*, Sofware Engineer
> *AZION*  |  Deliver. Accelerate. Protect.
> Office: +55 51 3083 8101   |  Mobile: +55 51
> *99907 0554*
>
> --
> 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
> 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/CAEM7gE2y%3DQHEJdbwUMbhmxDnY8%
> 2BEHSVdUKUJtgbGTX2UgoWKSA%40mail.gmail.com
> 
> .
>
> 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 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/CAPLHwtwGKQm_%3DMaft4vNnFQjf00Cmyw8UkLdq6W_aAmi5KVNgQ%40mail.gmail.com.
For more options, visit https://groups.googl

Re: Newbie : Object copy - weird error :-)

2018-07-13 Thread mickael . barbo
Thanks you Melvyn, this is it :-)

Have a nice day.

Regards

Le mardi 3 juillet 2018 00:34:14 UTC+2, Melvyn Sopacua a écrit :
>
> On vrijdag 29 juni 2018 09:44:40 CEST Mickael Barbo wrote:
>
>  
>
> > I try to create a way to archive (copy) the same object instance on an
>
> > other DataBase.
>
> > 
>
> > I followed this advice : # https://stackoverflow.com/
>
> > questions/21699707/python-how-to-copy-all-attibutes-from-
>
> > base-class-to-derived-one
>
>  
>
> That advice is for normal python classes. Django models have some 
> restrictions, one being that fields are special attributes. Messing with a 
> model's __init__() is not something you normally do as a model's class 
> creation is highly customized.
>
>  
>
> If you're really using 2 different databases, a model's save() operation 
> supports a `using` keyword that allows you to select the database 
> connection 
> <https://docs.djangoproject.com/en/2.0/topics/db/multi-db/#selecting-a-database-for-save>.
>  
> Archiving becomes really easy that way.
>
>  
>
>  
>
> -- 
>
> Melvyn Sopacua
>

-- 
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/a3f21016-62ab-43cc-9c3a-164797a602c9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


App structure : "One file - One object" - Is there a better way ?

2018-07-13 Thread Mickael Barbo
Hi !

*I like working with " 1 file - 1 object " (Object could be class,
function...).*
It simplify visibility, debug etc... and it's easy for me to *don't pollute
my brain* :-)


For exemple, I do :


In *class_.py file* :

class ():
a
b
c

from ._method1 import method1
from ._method2 import method2



and in *_method1.py file* :

def method1(self):
"my code"




*It works great, but is there a better way to do that ? is there a solution
to do that "automatically" ?*



I read lots of thinks about mixin, heritage, etc... but is there a better
way to split code to get a better granularity ?


Thanks for sharing your point ;-)

-- 
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/CAPLHwtyEAuCs1UcvLTzt1sXL7jpCQH%3DD_TGBgwiqbq7svc%3DNaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: App structure : "One file - One object" - Is there a better way ?

2018-07-14 Thread Mickael Barbo
Hi Anthony 😊

Thanks for sharing your experience.

"1 file one object doesn't mean what you think it means."

I hope you get the meaning I described 😉

"it normally means (for instance) defining one class (and ALL of it's
methods' in one file) - not importing methods into class definitions - I
have never seen anyone suggest that."

A method is a function ? a function an object ? right ?

My purpose is that *I prefer working on several "small" files containing 1
small function/object* and *NOT* *dealing with a "big" file* containing all
methods of class (for example). It's straightforward to find what I look
for.

Mixins and inheritance don't really help here - unless you are reusing the
same method in multiple classes - in which case you might have a mixin, or
an inheritance situation.
Agree 😊

If you have one or more methods that provide a useful extra behavior to one
or many classes (say that you have a set of methods that provide extra
formatting on some fields, then that would be a mixin
Ok

If you can identify one of your classes being an extension to another in
some way - so for instance you have a model for Customers, and you have a
model for your Gold Customers then you might well have an inheritance
situation - anywhere you can say Model A is a type of Model B that is
inheritance: Gold Customers are a type of Customer.
Ok

So, for you, *if you would reduce the size of files you are working on, how
would you do that ?*

For example, let's say you have a Customer class with 15 methods and the
file is about 1000 lines of code.
How to split this file in smaller files with 1 method per file ?


Thanks for your help Anthony, hoping to be as clear as possible.
Regards


2018-07-14 10:56 GMT+02:00 Anthony Flury :

> On 13/07/18 12:44, Mickael Barbo wrote:
>
>> Hi !
>> *
>> I like working with " 1 file - 1 object " (Object could be class,
>> function...).*
>> It simplify visibility, debug etc... and it's easy for me to *don't
>> pollute my brain* :-)
>>
>>
> 1 file one object doesn't mean what you think it means.
>
> it normally means (for instance) defining one class (and ALL of it's
> methods' in one file) - not importing methods into class definitions - I
> have never seen anyone suggest that.
>
> Mixins and inheritance don't really help here - unless you are reusing the
> same method in multiple classes - in which case you might have a mixin, or
> an inheritance situation.
>
> If you have one or more methods that provide a useful extra behavior to
> one or many classes (say that you have a set of methods that provide extra
> formatting on some fields, then that would be a mixin
>
> If you can identify one of your classes being an extension to another in
> some way - so for instance you have a model for Customers, and you have a
> model for your Gold Customers then you might well have an inheritance
> situation - anywhere you can say Model A is a type of Model B that is
> inheritance: Gold Customers are a type of Customer.
>
>
>> For exemple, I do :
>>
>>
>> In *class_.py file* :
>>
>> |
>> class():
>> a
>> b
>> c
>>
>> from.|_method1|importmethod1
>> from.|_method2| importmethod2
>> |
>>
>>
>>
>> and in |*_method1.py file* :
>> |
>> |
>> |
>> |
>> |
>> def|method1(self):
>> |
>> "my code"
>> |
>> |
>> |
>> |
>> |
>> |
>> |
>> |
>> |
>> |
>> *|It works great, but is there a better way to do that ? is there a
>> solution to do that "automatically" ?|*
>> *|
>> |*
>> *|
>> |*
>>
>> *||*
>> |I read lots of thinks about mixin, heritage, etc... but is there a
>> better way to split code to get a better granularity ?|
>> |
>> |
>>
>> ||
>> |Thanks for sharing your point ;-)|
>> ||*||*
>>
>>
>> --
>> 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 > django-users+unsubscr...@googlegroups.com>.
>> To post to this group, send email to django-users@googlegroups.com
>> <mailto: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/ms
>> gid/django-users/CAPLHwtyEAuCs1UcvLTzt1sXL7jpCQH%3DD_
>> TGBgwiqbq7svc%3DNaQ%40mail.gmail.com <https://g