ANYONE CAN HELP ME

2024-04-02 Thread arts maxwell Anderson
hello i have this error , i want to uppload multiple django image 
ValueError: FileInput doesn't support uploading multiple files.
any one can help me 

class FormImages(ModelForm):
multiple_image= forms.ImageField(widget=forms.FileInput(attrs= {
'multiple': True}))

class Meta:

model = Images
fields=['multiple_image']


#create prodcut in function 
def create_product(request):
form_image = FormImages()
form = FormCretaeProdcut()

if request.method == 'POST':
files = request.FILES.getlist('multiple_image')
form = FormCretaeProdcut(request.POST, request.FILES)
if form.is_valid():
product = form.save(commit=False)
product.save()
product.user = request.user
product.save()
for file in files :
Images.objects.create(product=product , images=file)
else:
form = FormCretaeProdcut()
return render(request, 'create_product.html', {'form':form, 'i_form':
form_image}) 

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c5cf6e10-68a1-4ceb-915d-df489db9b863n%40googlegroups.com.


Re: Django group

2022-09-27 Thread arts maxwell Anderson
Hello everyone
I'm Kouamou, Django developer,
Add me too
On this group

+237699812189

Le mar. 27 sept. 2022 à 16:59, sachin bhagat  a
écrit :

> Hii pls add me in group
>
> +918879399361
>
> On Tue, Sep 27, 2022, 8:11 PM Chris Adebiyi <
> adebiyichristophe...@gmail.com> wrote:
>
>> I'm interested, you can add me via +2348161201965
>>
>> On Tuesday, September 27, 2022, André Lewis 
>> wrote:
>>
>>> Hi! could you add me as well,
>>> +18762382482
>>>
>>> On Mon, 26 Sept 2022 at 20:45, Adolfo Duque León Fresneda
>>> (MisterRevenue)  wrote:
>>>
 hello if you can send me the link or add me +529381108109.. greeting
 from Mexico

 El lunes, 26 de septiembre de 2022 a las 7:54:05 UTC-5,
 farid...@gmail.com escribió:

> Hello fellow developers, I will be creating a WhatsApp group chat
> later in the day, So I will like my fellow Python Django Developers to 
> join
> the group. It will be much easier to discuss there and I will sacrifice
> myself out for anyone who need my service.
>
> God bless you all
> Enjoy your day
> Biliaminu
>
 --
 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 view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/1e19374b-65cb-4fd0-8533-7cc5751fc1f2n%40googlegroups.com
 
 .

>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAJN6x_jJ8w_QBGWOEaXjgO9fChofhZ28fBZ5t9b%2BWyGipSvmsw%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2B1vV4DKy0qJxmC0t5i1YbR4QAXeFkM_bwxJxXqBv%2B6ZssRByg%40mail.gmail.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABqfR%3D7DUOFPAsK_Y11Lq6JXWbRBBFe_nPS_baPRj8rbpWgQqg%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK83AirX-GkmSmMTecZmVWAAQaVmqd7pFnTeShkYtS%2B_n8WE1w%40mail.gmail.com.


Re:

2022-09-27 Thread arts maxwell Anderson
Hello l'm Django developer,
Add me
+237 699812189

Le mar. 27 sept. 2022 à 16:59, sachin bhagat  a
écrit :

> Hii pls add me in group
>
> +918879399361
>
> On Tue, Sep 27, 2022, 8:11 PM Chris Adebiyi <
> adebiyichristophe...@gmail.com> wrote:
>
>> I'm interested, you can add me via +2348161201965
>>
>> On Tuesday, September 27, 2022, André Lewis 
>> wrote:
>>
>>> Hi! could you add me as well,
>>> +18762382482
>>>
>>> On Mon, 26 Sept 2022 at 20:45, Adolfo Duque León Fresneda
>>> (MisterRevenue)  wrote:
>>>
 hello if you can send me the link or add me +529381108109.. greeting
 from Mexico

 El lunes, 26 de septiembre de 2022 a las 7:54:05 UTC-5,
 farid...@gmail.com escribió:

> Hello fellow developers, I will be creating a WhatsApp group chat
> later in the day, So I will like my fellow Python Django Developers to 
> join
> the group. It will be much easier to discuss there and I will sacrifice
> myself out for anyone who need my service.
>
> God bless you all
> Enjoy your day
> Biliaminu
>
 --
 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 view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/1e19374b-65cb-4fd0-8533-7cc5751fc1f2n%40googlegroups.com
 
 .

>>> --
>>> 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 view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAJN6x_jJ8w_QBGWOEaXjgO9fChofhZ28fBZ5t9b%2BWyGipSvmsw%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CA%2B1vV4DKy0qJxmC0t5i1YbR4QAXeFkM_bwxJxXqBv%2B6ZssRByg%40mail.gmail.com
>> 
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABqfR%3D7DUOFPAsK_Y11Lq6JXWbRBBFe_nPS_baPRj8rbpWgQqg%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK83Aiq1cxQYty6KiV1LCWr4bE15vJXCAaebpyoroLpEt_-Fcg%40mail.gmail.com.


Re: Aad me to the groso

2022-09-27 Thread arts maxwell Anderson
Hello l'm Django developer,

+237 699812189

Le mar. 27 sept. 2022 à 16:41,  a écrit :

> Ok, add me to the group +54 9 1164446437
>
> Enviado desde mi iPhone
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3AFC9305-35C3-495C-A936-79972EBBF431%40gmail.com
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK83Aiohr5xYjOgfNdK7Dw0wWyxDUQhkByS%2Burcpwsdkg8ydSg%40mail.gmail.com.


Re: Django DB connectivity to DB running in different server.

2022-09-12 Thread arts maxwell Anderson
hello guys i need to django ? anyone can help me

2022-09-12 8:29 UTC+01:00, Anh Nguyen :
> You should ask djongo group
>
> On Mon, 12 Sep 2022 at 13:29 Prabakaran Balaji 
> wrote:
>
>> *Hello Django Users,*
>>
>> Need some support on database connectivity in my django application. It's
>> trying to connect with localhost even after specifying the IP address.
>> Getting below error, could someone pls look into this?
>>
>> *Error - *
>> Watching for file changes with StatReloader
>> Performing system checks...
>>
>> System check identified no issues (0 silenced).
>> Exception in thread django-main-thread:
>> Traceback (most recent call last):
>>   File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
>> self.run()
>>   File "/usr/lib/python3.6/threading.py", line 864, in run
>> self._target(*self._args, **self._kwargs)
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/utils/autoreload.py",
>> line 64, in wrapper
>> fn(*args, **kwargs)
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
>> line 121, in inner_run
>> self.check_migrations()
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/core/management/base.py",
>> line 486, in check_migrations
>> executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/db/migrations/executor.py",
>> line 18, in __init__
>> self.loader = MigrationLoader(self.connection)
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/db/migrations/loader.py",
>> line 53, in __init__
>> self.build_graph()
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/db/migrations/loader.py",
>> line 220, in build_graph
>> self.applied_migrations = recorder.applied_migrations()
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py",
>> line 77, in applied_migrations
>> if self.has_table():
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/db/migrations/recorder.py",
>> line 56, in has_table
>> tables = self.connection.introspection.table_names(cursor)
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/db/backends/base/introspection.py",
>> line 52, in table_names
>> return get_names(cursor)
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/django/db/backends/base/introspection.py",
>> line 47, in get_names
>> return sorted(ti.name for ti in self.get_table_list(cursor)
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/djongo/introspection.py", line
>> 47, in get_table_list
>> for c in cursor.db_conn.list_collection_names()
>>   File "/app/pkg/venv/lib/python3.6/site-packages/pymongo/database.py",
>> line 875, in list_collection_names
>> return [result["name"] for result in
>> self.list_collections(session=session, **kwargs)]
>>   File "/app/pkg/venv/lib/python3.6/site-packages/pymongo/database.py",
>> line 827, in list_collections
>> return self.__client._retryable_read(_cmd, read_pref, session)
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/pymongo/mongo_client.py", line
>> 1364, in _retryable_read
>> server = self._select_server(read_pref, session, address=address)
>>   File
>> "/app/pkg/venv/lib/python3.6/site-packages/pymongo/mongo_client.py", line
>> 1196, in _select_server
>> server = topology.select_server(server_selector)
>>   File "/app/pkg/venv/lib/python3.6/site-packages/pymongo/topology.py",
>> line 251, in select_server
>> servers = self.select_servers(selector, server_selection_timeout,
>> address)
>>   File "/app/pkg/venv/lib/python3.6/site-packages/pymongo/topology.py",
>> line 212, in select_servers
>> server_descriptions = self._select_servers_loop(selector,
>> server_timeout, address)
>>   File "/app/pkg/venv/lib/python3.6/site-packages/pymongo/topology.py",
>> line 229, in _select_servers_loop
>> % (self._error_message(selector), timeout, self.description)
>> pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111]
>> Connection refused, Timeout: 30s, Topology Description:
>> > Unknown,
>> servers: [> rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection
>> refused',)>]>
>>
>> *settings.py - DB part*
>>
>> *-*
>>
>> DATABASES = {
>> 'default': {
>> 'ENGINE': 'djongo',
>> 'NAME': 'app_db',
>> 'USER': 'app_user',
>> 'PASSWORD': 'app_pwd',
>> 'HOST': '10.111.0.1',
>> 'PORT': '27017'
>> }
>> }
>>
>>
>> Thanks,
>> Prabakaran
>>
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAK7fxT_UiuBQpoesAR4W12epW2dH9tfsAh4Q8kqycPExANTsEg%40mail.gmail.com
>> 

Re: What Programming Language should i learn

2022-09-10 Thread arts maxwell Anderson
i need job in django anyone 

Le jeudi 1 septembre 2022 à 20:13:10 UTC+1, subtitle indo a écrit :

> We have received your message and will be in touch withinSorry not to 
> reply sooner.Sorry not to reply sooner.Sorry not to reply sooner.
>
> On Tue, Aug 30, 2022 at 3:59 PM Shailesh Yadav  
> wrote:
>
>> LOL, You mean you learned Django without first learning Python?.
>>
>> It depends but My suggestion would be to learn Python and later learn C++ 
>> (So then you will get much clarity on what is the difference between these 
>> two languages). Then after that, you can learn Data structure and 
>> Algorithms.
>>
>>
>> Thanks & Regards
>> Shailesh Yadav
>> +91-9920886044 <+91%2099208%2086044>
>>
>>   [image: Linkedin] 
>>  
>>
>>
>>
>> On Tue, Aug 30, 2022 at 8:12 PM Ryan Nowakowski  
>> wrote:
>>
>>> On Tue, Aug 30, 2022 at 03:35:26PM +0100, fawemimo olawale wrote:
>>> > Which of these  programming language should i learn
>>> > 
>>> > Please I need counselling on this two language though i have prior
>>> > knowledge on Python Web Framework (Django) as a beginner's but i want
>>> > Backend Language
>>> > 
>>> > JAVA or ASP.Net
>>>
>>> Python!  But of course this list is biased :)
>>>
>>> -- 
>>> 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 view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/20220830144155.GD1858%40fattuba.com
>>> .
>>>
>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAMQ-AEUg0gV0CXmeGCogZ2s1hkGsBJoC5t9kwYNvCBqRKmczcg%40mail.gmail.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/79bbbefc-30ee-49dc-900a-0e0a8a1e612bn%40googlegroups.com.


Re: attempt to write a readonly database

2020-12-23 Thread Bryan Anderson bautista garcia
hello, I don't know who you are, you're the wrong person

El mié, 23 de dic. de 2020 a la(s) 11:19, Parul. (parul.281...@gmail.com)
escribió:

> OperationalError at /users/
> Request Method: POST
> Request URL: http://localhost:8000/users/
> Django Version: 3.0.3
> Exception Type: OperationalError
> Exception Value:
>
> attempt to write a readonly database
>
> Exception Location: 
> C:\Users\parul\anaconda\envs\MyDjangoEnv\lib\site-packages\django\db\backends\sqlite3\base.py
> in execute, line 396
> Python Executable: C:\Users\parul\anaconda\envs\MyDjangoEnv\python.exe
> Python Version: 3.8.5
> Python Path:
>
> ['C:\\Users\\parul\\Desktop\\Djangoforms\\ProTwo',
>  'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv\\python38.zip',
>  'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv\\DLLs',
>  'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv\\lib',
>  'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv',
>  'C:\\Users\\parul\\anaconda\\envs\\MyDjangoEnv\\lib\\site-packages']
>
> Server time: Wed, 23 Dec 2020 16:14:46 +
>
>
>
> ->>> Also, i checked the properties in db.sqlite3, all the
> permissions are checked...write permission also
> can anyone help
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHjHRFoBMq5VCKnBPiCEgSrLvZ7P0vvwd5Ah-_cDOv8kX1oKhg%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACs2VvYWAkaOpcVAVTm5TKVixq%2BuUhejD-1ejUaVGrK1V31oUQ%40mail.gmail.com.


Re: saving data from both a model and a derived model

2017-05-24 Thread Jim Anderson
Hi James,

I'm attaching the stacktrace as you requested.

The call to rs_template.save() is made from a django view.  rs_template is
an instance of a class RSTemplate which is derived from STemplate.
STemplate is derived from PriorityItemType. PriorityItemType is derived
from ItemType. ItemType is derived from models.Model. PriorityItemType and
ItemType are classes that are part of a library and which I have minimal
control over, so figure them as constants that cannot be changed.

Jim


The relevant code is as follows:

>From ItemType.py

[code]
class ItemType(models.Model):
...
name = models.CharField('Name', max_length=100, unique=True,
db_index=True)
[/code]

>From PriorityItemType.py

[code]
class PriorityItemType(ItemType):
   ...
   priority = models.IntegerField('Priority', default=1)
[/code]

>From STemplate.py

[code]
class STemplate(PriorityItemType):
...
backend = models.ForeignKey('siggy.SBackend', null=True, blank=True)
[/code]

>From RSTemplate.py

[code]
class RSTemplate(STemplate):
   ...
   role = models.CharField(max_length=50)
[code]

>From RSPrepView.py

[code]
class RSPrewView(View):
   ...

   for t in templates.templates:
try:
rs_template = RSTemplate.objects.get(name=t.filename)
except RSTemplate.DoesNotExist:
rs_template = RSTemplate()
rs_template.name = t.filename
rs_template.role = "RS Template"
rs_template.save()
[/code]



On Wed, May 24, 2017 at 3:36 AM, James Schneider 
wrote:

>
>
> On Tue, May 23, 2017 at 3:44 PM,  wrote:
>
>> I have a model class, 'A_base', and a 2nd model class, 'A_derived'. When
>> I save an object of A_derived, I want the data from both my base and
>> derived class to be saved.
>>
>> Example code looks like this:
>>
>> class A_base(models.model):
>> name = models.CharField(max_length=50)
>>
>> class A_derived(A_base):
>> role = models.CharField(max_length=50)
>>
>>
>> So when I call save(), I want to save an instance of the derived object,
>> including the data in the base class into my sqlite3 database. I would like
>> my code to look like this:
>>
>> ...
>> derived_obj = A_derived.objects.get(name="john")
>> derived_obj.role = "parent"
>> derived_obj.save()
>> ...
>>
>> My question is whether the save method will save 'role' to the A_derived
>> table and save 'name' to the A_base table? Or do I have to override the
>> save method so that it saves 'role' and then calls the base class save
>> method to save 'name'?
>>
>>
> No, you have created two separate (but related) models. A_base has a model
> field of 'name', and A_derived has model fields 'name' and 'role'. Since
> you are inheriting from a non-abstract parent model, there is an implied
> OneToOne relationship between the two models, see the following:
> https://docs.djangoproject.com/en/1.11/topics/db/models/#multi-table-
> inheritance
>
> I'm not a big fan of this implied behavior, but it hasn't been problematic
> for me because I make heavy use of abstract model classes.
>
> If you do not want the implied relationship between the two models, create
> an abstract base class matching A_base and have both of your models inherit
> from it (A_base would be an empty model in this case, most likely).
>
> From a Django perspective, these two are completely independent
> models/entities (aside from the OneToOne relationship). A_derivied will
> have its own name and role. A_base also has it's own name, but will not be
> able to contain a role.
>
> To achieve the behavior you want, when A_derived is saved, you'll need to
> either create a new A_base object and set the 'name' field to the same
> value, or query for an existing A_base object and change/save the 'name'
> field. Keep in mind that the two values are not connected to each other.
> Changing the 'name' field on the same A_derived class later will NOT change
> the 'name' field on an A_base object automatically, you would need to
> provide such logic on one or both models, depending on the direction of the
> dependency you wish to create.
>
>
>> I tried doing this using the default save method and it created a stack
>> trace, so I'm guessing that I am expecting too much from the default save
>> method.
>>
>>
> Post the entire stack trace and we may be able to better illuminate the
> issue.
>
> -James
>
> --
> 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/QPo8MFXNdAc/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/CA%2Be%2BciXDpbGmmpqbcDC_iip

Re: tutorial on using dbshell?

2017-05-23 Thread Jim Anderson
James,

Thank you, again.

I have install the sqlite command line package and all is working for me.

Jim A.

On Mon, May 22, 2017 at 6:35 PM, James Schneider 
wrote:

>
>
> On May 22, 2017 3:07 PM, "Jim Anderson"  wrote:
>
> Hi James,
>
> I'm looking at the sqlite3 documentation now, but I'm still not quite sure
> how to run the dbshell. Once I am in the shell, I assume that I can run
> sqlite3 commands as needed. But when I enter:
>
> *% python manage.py dbshell*
>
> I get the following error messages:
>
>
>
> *setting.py: BASE_DIR =  /home/jja/...FINISHED settings.pyCommandError:
> You appear not to have the 'sqlite3' program installed or on your path.*
>
> Am I invoking it properly? Do I have to change my configuration?
>
>
> From a Django perspective, it looks correct. You'll need to install the
> sqlite3 management package do that Django has access to it. In most cases,
> if you are able to run the sqlite3 command by itself, Django should be able
> to find it. How you install it is going to be dependent on your OS. Linux
> distributions should have it really available in their package
> repositories, and the necessary package for Windows should be available on
> it's project page.
>
> -James
>
>
> --
> 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/YYgAsqFhT8w/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/CA%2Be%2BciXENhSCg6w4YRfC6xpc5mg7BQmR
> k22ODqu%2BSCw%3DxEjLBQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXENhSCg6w4YRfC6xpc5mg7BQmRk22ODqu%2BSCw%3DxEjLBQ%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 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/CAB5UADH%2BMwRnOMx9RnoNE75_tD_pJYyMRhoObXEWMPdz7GQJ3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: tutorial on using dbshell?

2017-05-22 Thread Jim Anderson
Hi James,

I'm looking at the sqlite3 documentation now, but I'm still not quite sure
how to run the dbshell. Once I am in the shell, I assume that I can run
sqlite3 commands as needed. But when I enter:

*% python manage.py dbshell*

I get the following error messages:



*setting.py: BASE_DIR =  /home/jja/...FINISHED settings.pyCommandError: You
appear not to have the 'sqlite3' program installed or on your path.*

Am I invoking it properly? Do I have to change my configuration?

Jim A.


On Mon, May 22, 2017 at 5:28 PM, James Schneider 
wrote:

>
>
> On May 22, 2017 2:20 PM,  wrote:
>
>
> I'm working with Django 1.10.3 and I'm trying to look at the database
> tables generated by Django using makemigrations and migrate. I was looking
> to use 'python manage.py sql', but it looks like that is no longer
> available. In a recent question to Django users, I was advised to use
> dbshell which I am planning to do, but thus fair I have not found and
> instructions or a tutorial on how to use deshell. Can someone point me to
> instructions?
>
>
> The dbshell command is simply a convenience command for opening the
> standard management console for your specific database. That interface will
> be different depending on the type of database you are using (MySQL,
> Postgres, or SQLite). You can find the commands for each database
> management tool by searching for " commands tutorial", as an
> example.
>
> -James
>
> --
> 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/YYgAsqFhT8w/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/CA%2Be%2BciWZyW7Q_xzDYrEBFzAHSjDD_
> XBBD%2Bh2XGbOCoePcFLueA%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/CAB5UADGurJko5ZHWtott%2BRO2%2BtO_%2BjOb2vbvYd3%2BEf1rE5S-OA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django.db.migrations.graph.NodeNotFoundError:

2016-12-23 Thread Collin Anderson
Hi,

Do you want to copy and paste your error message? (I assume it's similar, 
but it might have some better clues.)

My guess you have a migration that's referencing a migration file that was 
deleted or something.

Collin

On Thursday, December 22, 2016 at 7:33:48 PM UTC-6, skerdi wrote:
>
> I have the same problem, but with an existing project. I've deleted 
> migrations and the database and shows the same problem.
> I have 2+ hours searching but I haven't fixed it. 
>
> On Wednesday, June 1, 2016 at 12:58:55 AM UTC+2, Bose Yi wrote:
>>
>> When new project start,   commands makemigrations and runserver  get 
>>  error message.I do not know what I did wrong.   I cannot find solution 
>> to fix it.  Please  any suggestion ? 
>>
>>
>> 
>>
>> System check identified no issues (0 silenced).
>>
>> Unhandled exception in thread started by 
>>
>> Traceback (most recent call last):
>>
>>   File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 
>> 229, in wrapper
>>
>> fn(*args, **kwargs)
>>
>>   File 
>> "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py",
>>  
>> line 116, in inner_run
>>
>> self.check_migrations()
>>
>>   File 
>> "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py",
>>  
>> line 168, in check_migrations
>>
>> executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
>>
>>   File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", 
>> line 19, in __init__
>>
>> self.loader = MigrationLoader(self.connection)
>>
>>   File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", 
>> line 47, in __init__
>>
>> self.build_graph()
>>
>>   File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", 
>> line 318, in build_graph
>>
>> _reraise_missing_dependency(migration, parent, e)
>>
>>   File "C:\Python27\lib\site-packages\django\db\migrations\loader.py", 
>> line 288, in _reraise_missing_dependency
>>
>> raise exc
>>
>> django.db.migrations.graph.NodeNotFoundError: Migration 
>> auth.0007_user_following dependencies reference nonexistent parent node 
>> (u'account', u'0003_contact')
>>
>

-- 
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/31ba0cc8-a56b-41c3-a5ec-7991b1bffb57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ProgrammingError: relation "auth_user" does not exist.

2016-12-23 Thread Collin Anderson
Hi,

Have you tried running ./manage.py makemigrations and then ./manage.py 
migrate? That's needed to actually create the table.

Collin

On Thursday, December 22, 2016 at 12:25:58 PM UTC-6, Biplab Gautam wrote:
>
> I tried to set up custom user model by inheriting from AbstractBaseUser as 
> instructed in django documentation, but I am encountering relation 
> "auth_user" does not exist error.
>
> #models.py
> from django.db import models
> from django.contrib.auth.models import (BaseUserManager, AbstractBaseUser)
>
> class MyUserManager(BaseUserManager):
> def create_user(self, email, date_of_birth, password=None):
> """Creates and saves the user with the given email, DOB and password"""
> if not email:
> raise ValueError('Users must have an email address')
> user = 
> self.model(email=self.normalize_email(email),date_of_birth=date_of_birth,)
> user.set_password(password)
> user.save(using=self._db)
> return user
>
> def create_superuser(self, email, date_of_birth, password):
> """Creates and saves a superuser with the given email, date of birth and 
> password."""
> user = self.create_user(email, password=password, 
> date_of_birth=date_of_birth)
> user.is_admin = True
> user.save(using=self._db)
> return user
>
> class MyUser(AbstractBaseUser):
> email = models.EmailField(verbose_name='email address', max_length=255, 
> unique=True,)
> date_of_birth = models.DateField()
> is_active = models.BooleanField(default=True)
> is_admin = models.BooleanField(default=False)
>
> objects = MyUserManager()
>
> USERNAME_FIELD = 'email'
> REQUIRED_FIELDS = ['date_of_birth']
>
> def get_full_name(self):
> return self.email
> def get_short_name(self):
> return self.email
> def __str__(self):
> return self.email
> def has_perm(self, perm, obj=None):
> return True
> def has_module_perms(self, app_label):
> return True
> @property
> def is_staff(self):
> return self.is_admin
>
> #admin.py
> from django import forms
> from django.contrib import admin
> from django.contrib.auth.models import Group
> from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
> from django.contrib.auth.forms import ReadOnlyPasswordHashField
>
> from user.models import MyUser
>
> class UserCreationForm(forms.ModelForm):
> """A form for creating new users. Includes all the required fields, plus a 
> repeated password."""
> password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
> password2 = forms.CharField(label='Password confirmation', 
> widget=forms.PasswordInput)
>
> class Meta:
> model = MyUser
> fields = ('email', 'date_of_birth')
>
> def clean_password2(self):
> """Check that the two password entries match"""
> password1 = self.cleaned_data.get("password1")
> password2 = self.cleaned_data.get("password2")
> if password1 and password2 and password1 != password2:
> raise forms.ValidationError("Passwords don't match")
> return password2
>
> def save(self, commit=True):
> #Save the provided password in hashed format
> user = super(UserCreationForm, self).save(commit=False)
> user.set_password(self.cleaned_data["password1"])
> if commit:
> user.save()
> return user
> class UserChangeForm(forms.ModelForm):
> """A form for updating users. Includes all the fields on the user, but 
> replaces the password field with admin's password hash display field."""
> password = ReadOnlyPasswordHashField()
> class Meta:
> model = MyUser
> fields = ('email', 'password', 'date_of_birth', 'is_active', 'is_admin')
> def clean_password(self):
> return self.initial["password"]
> # Regardless of what the user provides, return the initial value.
> # This is done here, rather than on the field, because the
> # field does not have access to the initial value
>
>
>
> class UserAdmin(BaseUserAdmin):
> # The forms to add and change user instances
> form = UserChangeForm
> add_form = UserCreationForm
>
> # The fields to be used in displaying the User model.
> # These override the definitions on the base UserAdmin
> # that reference specific fields on auth.User.
> list_display = ('email', 'date_of_birth', 'is_admin')
> list_filter = ('is_admin',)
> fieldsets = (
> (None, {'fields': ('email', 'password')}),
> ('Personal info', {'fields': ('date_of_birth',)}),
> ('Permissions', {'fields': ('is_admin',)}),
> )
> # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
> # overrides get_fieldsets to use this attribute when creating a user.
> add_fieldsets = (
> (None, {
> 'classes': ('wide',),
> 'fields': ('email', 'date_of_birth', 'password1', 'password2')}
> ),
> )
> search_fields = ('email',)
> ordering = ('email',)
> filter_horizontal = ()
>
> # Now register the new UserAdmin...
> admin.site.register(MyUser, UserAdmin)
> # ... and, since we're not using Django's built-in permissions,
> # unregister the Group model from admin.
> admin.site.unregister(Group)
>
> #views.py
> from django.

Re: existing database connectivity

2016-12-23 Thread Collin Anderson
Hi,

You could try re-installing psycopg2 to see if that fixes it.

Collin

On Thursday, December 22, 2016 at 1:55:53 AM UTC-6, Rasika wrote:
>
>
> I am followed the steps as I am getting in tutorials
> when I run the command :
> python manage.py migrate
> this is giving me following error
>
> from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
> ImportError: DLL load failed: The specified module could not be found.
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "manage.py", line 22, in 
> execute_from_command_line(sys.argv)
> On Monday, December 19, 2016 at 7:50:19 PM UTC+5:30, Derek wrote:
>>
>> Suggest you look at Django authentication:
>>
>> https://docs.djangoproject.com/en/1.10/topics/auth/customizing/
>> "Authentication backends provide an extensible system for when a username 
>> and password stored with the user model need to be authenticated against a 
>> different service than Django’s default."
>>
>> It also seems as if your Django project was not set up properly (again 
>> from the docs):
>>
>> "By default, the required configuration is already included in the 
>> settings.py generated by django-admin startproject, these consist of two 
>> items listed in your INSTALLED_APPS setting:
>> 1. 'django.contrib.auth' contains the core of the authentication 
>> framework, and its default models.
>> 2.  'django.contrib.contenttypes' is the Django content type system, 
>> which allows permissions to be associated with models you create"
>>
>>
>> On Monday, 19 December 2016 13:34:39 UTC+2, Rasika wrote:
>>>
>>> Hello all,
>>>  I am using Django framework for our website.I am stuck on the 
>>> database connectivity.I want to change the default database sqlite with our 
>>> for test purpose but in that also I am getting problems.
>>>  My aim is I have to use our compnies database so that already 
>>> registered users have not to create their account again
>>> AsDjango already comes with its own builtin apps for login,logout 
>>> authentication and registration .Also I am not able to find the 
>>> 'django.contrib.auth',
>>> 'django.contrib.contenttypes',
>>> 'django.contrib.sessions',
>>> 'django.contrib.sites',
>>> 'django.contrib.admin',
>>> etc and all default apps also.
>>> Please help me.
>>>
>>> Thank you.
>>>
>>

-- 
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/89215907-1332-4674-9434-865a49e28d41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: MultiWidget not rendering

2016-12-23 Thread Collin Anderson
Hi,

I think you want something like this.

class Fourteen(forms.Form):
mywidget = forms.DateField(widget=DateSelectorWidget())

Collin

On Monday, December 19, 2016 at 1:13:17 PM UTC-6, Farhan Khan wrote:
>
> Unfortunately that does not display.
> In the template I had it as {{ fourteen }} and saw it was rendering 
> everything but my custom widget.
>
> --
> Farhan Khan
> PGP Fingerprint: 4A78 F071 5CB6 E771 B8D6 3910 F371 FE22 3B20 B21B
>
> On Mon, Dec 19, 2016 at 2:02 PM, Matthew Pava  > wrote:
>
>> I’m not that familiar with MultiWidget, but it would seem that your print 
>> statement should be:
>>
>> print(fourteen.mywidget)
>>
>>  
>>
>> *From:* django...@googlegroups.com  [mailto:
>> django...@googlegroups.com ] *On Behalf Of *Farhan Khan
>> *Sent:* Monday, December 19, 2016 11:40 AM
>> *To:* Django users
>> *Subject:* MultiWidget not rendering
>>
>>  
>>
>> Hi all!
>>
>> I am trying to get a MultiWidget with two TextFields ,however I am not 
>> able to get anything to render. Here is my code.
>>
>>  
>>
>> from django import forms
>> from django.forms import widgets
>>
>> class DateSelectorWidget(widgets.MultiWidget):
>> def __init__(self, attrs=None):
>> _widgets = (forms.TextInput(),
>> forms.TextInput())
>> super(DateSelectorWidget, self).__init__(_widgets, attrs)
>>
>> def format_output(self, rendered_widgets):
>> return ''.join(rendered_widgets)
>>
>> class Fourteen(forms.Form):
>> mywidget = DateSelectorWidget()
>>
>>  
>>
>> In the shell I will do:
>>
>>  
>>
>> >>> fourteen = Fourteen()
>>
>> >>> print(fourteen)
>>
>>  
>>
>> >>> 
>>
>>
>> Nothing will render. I suspect that I need to manually render the HTML, 
>> but the documentation 
>>  
>> is fairly light on this topic.
>>
>>  
>>
>> Any assistance would be greatly appreciated!
>>
>> -- 
>> 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/86bebdb4-1d45-4612-84d1-456f86942709%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/hUmvw-mdaiY/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/ebd9f58fca3a4009abcfd05e16fca9dc%40ISS1.ISS.LOCAL
>>  
>> 
>> .
>>
>> 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/9eaec86d-7df1-4fae-bf9b-6d8af62e6154%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ImportError at/ No module name

2015-11-07 Thread Scott Anderson
We just tripped across something similar here as well. The person doing the 
tutorial had flipped the 'startup' and 'put "blog" in the INSTALLED_APPS' 
steps of the tutorial. She commented out 'blog' from INSTALLED_APPS and 
startapp worked as intended.

-scott

On Sunday, August 11, 2013 at 8:11:11 PM UTC-4, Pranay Shah wrote:
>
> I just want to thank everyone. I had an error "no module name image" since 
> yesterday nite. I googled and found out that I need to install python image 
> library. I did that. I still continued getting error. Just then I came 
> across this post where someone was getting "no module... blog". I read it 
> and found out the prob. Initially I had an "image" view which I deleted 
> last nite as I was no longer gonna use it. But I didnt remove its mapping 
> form the urls.py. I commented the lines for image - views and it worked.
>
> Thank you all. Now I shall start working on the actual stuff which I was 
> supposed to work from last nite. Its actually my internship homework.
>
> Thank you once again. 
>
> On Thursday, 20 December 2012 05:27:42 UTC-8, djangobie wrote:
>>
>> Hi, I have just started practicing a tutorial for buidling a  basic blog 
>> ( 
>> http://www.djangorocks.com/tutorials/how-to-create-a-basic-blog-in-django/starting-your-application.html
>>  )
>>
>> Did exactly the same (except, using 'djangopractice' as project name 
>> instead of 'djangorocks')
>> Actually It also did run twice, but than started showing ImportError.
>>
>> My files:
>> 
>> ***settings.py***
>> 
>> # Django settings for djangopractice project.
>> #import os, django
>> #DJANGO_ROOT = os.path.dirname(os.path.realpath(django.__file__))
>> #SITE_ROOT = os.path.dirname(os.path.realpath('__file__'))
>>
>> DEBUG = True
>> TEMPLATE_DEBUG = DEBUG
>>
>> ADMINS = (
>> # ('Your Name', 'your_...@example.com'),
>> )
>>
>> MANAGERS = ADMINS
>>
>> DATABASES = {
>> 'default': {
>> 'ENGINE': 'django.db.backends.mysql', # Add 
>> 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
>> 'NAME': 'djangopractice',  # Or path to 
>> database file if using sqlite3.
>> 'USER': 'root',  # Not used with sqlite3.
>> 'PASSWORD': '1290',  # Not used with sqlite3.
>> 'HOST': '',  # Set to empty string for 
>> localhost. Not used with sqlite3.
>> 'PORT': '',  # Set to empty string for 
>> default. Not used with sqlite3.
>> }
>> }
>>
>> # Local time zone for this installation. Choices can be found here:
>> # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
>> # although not all choices may be available on all operating systems.
>> # In a Windows environment this must be set to your system time zone.
>> TIME_ZONE = 'Asia/Karachi'
>>
>> # Language code for this installation. All choices can be found here:
>> # http://www.i18nguy.com/unicode/language-identifiers.html
>> LANGUAGE_CODE = 'en-us'
>>
>> SITE_ID = 1
>>
>> # If you set this to False, Django will make some optimizations so as not
>> # to load the internationalization machinery.
>> USE_I18N = True
>>
>> # If you set this to False, Django will not format dates, numbers and
>> # calendars according to the current locale.
>> USE_L10N = True
>>
>> # If you set this to False, Django will not use timezone-aware datetimes.
>> USE_TZ = True
>>
>> # Absolute filesystem path to the directory that will hold user-uploaded 
>> files.
>> # Example: "/home/media/media.lawrence.com/media/"
>> MEDIA_ROOT = ''
>>
>> # URL that handles the media served from MEDIA_ROOT. Make sure to use a
>> # trailing slash.
>> # Examples: "http://media.lawrence.com/media/";, "
>> http://example.com/media/";
>> MEDIA_URL = ''
>>
>> # Absolute path to the directory static files should be collected to.
>> # Don't put anything in this directory yourself; store your static files
>> # in apps' "static/" subdirectories and in STATICFILES_DIRS.
>> # Example: "/home/media/media.lawrence.com/static/"
>> STATIC_ROOT = ''
>>
>> # URL prefix for static files.
>> # Example: "http://media.lawrence.com/static/";
>> STATIC_URL = '/static/'
>>
>> # Additional locations of static files
>> STATICFILES_DIRS = (
>> # Put strings here, like "/home/html/static" or 
>> "C:/www/django/static".
>> # Always use forward slashes, even on Windows.
>> # Don't forget to use absolute paths, not relative paths.
>> )
>>
>> # List of finder classes that know how to find static files in
>> # various locations.
>> STATICFILES_FINDERS = (
>> 'django.contrib.staticfiles.finders.FileSystemFinder',
>> 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
>> #'django.contrib.staticfiles.finders.DefaultStorageFinder',
>> )
>>
>> # Make this unique, and don't share it with anybody.
>> SECRET_KEY = '@io!2+0*rw1o0tjq%t5zb8e$v(wf3p#yk_8#lb^%hrerzijwt1'
>>
>> # List of callables that know how to import templates from various 

Re: return values from static files to django admin

2015-11-05 Thread Collin Anderson
Hi,

You may need to also calculate the possible options in python. Some hacky 
code that might help:

class AdminRoutingInlineForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(AdminRoutingInlineForm, self).__init__(*args, **kwargs)
field1 = self.data.get('field1', '')
CHOICES = [('a', '%s any' % field1),('b', '%s blah' % field1),] 
self.fields['choice_text'].choices = CHOICES

Collin

On Monday, November 2, 2015 at 9:32:58 PM UTC+1, dc wrote:
>
> I tried that. But in that case I need to declare choices in models.py for 
> that field (so that the field is displayed as a dropdown in admin) and then 
> django doesn't accept any string that's not part of the choices list. I am 
> pretty sure I am missing something here.
>
> On Mon, Nov 2, 2015 at 2:55 PM, Andreas Kuhne  > wrote:
>
>> Hi,
>>
>> Yes you could just populate the dropdown list with javascript. 
>>
>> Regards,
>>
>> Andréas
>>
>> 2015-11-02 17:27 GMT+01:00 dc >:
>>
>>> Thanks a lot. Let me look into it.
>>>
>>> Is there any other way I can populate my choice list with user input?
>>>
>>> On Monday, November 2, 2015 at 10:19:22 AM UTC-5, Andréas Kühne wrote:

 Hi,

 What you are suggesting doesn't work. You can't communicate with the 
 django backend via javascript if you don't use a lot of ajax requests. I 
 would check django-smart-selects and see if you could use that?

 Regards,

 Andréas

 2015-11-02 15:57 GMT+01:00 dc :

> Any lead will be extremely helpful. I am still stuck. :(
>
> On Thursday, October 29, 2015 at 11:40:32 PM UTC-4, dc wrote:
>>
>> I have declared a charfield 'choice_text' in one of my models. I want 
>> to convert it to a dropdown box in django admin. The choices in the 
>> dropdown list depend on user input to a textbox defined in another 
>> model class. I have a javascript (declared  as Media class inside a 
>> ModelAdmin class) that reads user input in the textbox. But I am unable 
>> to 
>> this choice list back from .js file to django admin. How do I do that? 
>> Thanks in advance.
>>
>> I have tried this.
>>
>> *models.py*
>> class Routing(models.Model):
>> choice_text = models.CharField(_('Choices'), max_length=100, 
>> default="(any)", null=False)
>>
>> *admin.py*
>> class AdminRoutingInlineForm(forms.ModelForm):
>> def __init__(self, *args, **kwargs):
>> super(AdminRoutingInlineForm, self).__init__(*args, **kwargs)
>> CHOICES = [('a', 'any'),('b', 'blah'),] * // override 
>> this with choices from populate_dropdown.js (code below)*
>> self.fields['choice_text'].choices = CHOICES
>>
>> class RoutingInlineAdmin(StackedInline):
>> form = AdminRoutingInlineForm
>> fields = (('choice_text', 'next'),)
>> model = Routing
>>
>>
>> class FormModelAdmin(ModelAdmin):
>> inlines = [RoutingInlineAdmin]
>>
>> class Media:
>> js= ("sforms/admin/populate_dropdown.js",)
>>
>>
>> *populate_dropdown.js*
>> (function($) {
>> $(document).ready(function() {
>>
>> $("[id^=id_fields-][id$=_options_0]").each(function(){ *  
>> // user input from this field will be used as choices*
>> choices = '(any),' + $(this).val().split("\n");
>> alert(choices);
>> 
>> *// send this choices back to admin.py and override CHOICES 
>> in AdminRoutingInlineForm class*
>> });  
>> });
>>  
>>
>>
>> -- 
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/6ef56f22-dce0-4a85-b348-381b3a93e88f%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...@googlegroups.com .
>>> To post to this group, send email to django...@googlegroups.com 
>>> .
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/24ac486e-08fa-42cd-a426-bda97246693c%40googlegroups.com
>>>  

Re: jquery and django template

2015-11-05 Thread Collin Anderson
Hi,

Are you trying to show the user what filters are being applied to the data, 
or are you trying to filter the data based on a user selection?

Collin

On Monday, November 2, 2015 at 2:51:36 AM UTC+1, varun naganathan wrote:
>
> I basically have the database entries in the namespace of my template.I 
> basically need to get the filter i want to apply on the databse entry using 
> data available from user selection(using jquery).Any suggestions on how i 
> can achieve this?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/37a720f5-020b-49ec-8119-120da188ca5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django bootstrap3_datetime widget in admin site doesn't pass form data

2015-11-05 Thread Collin Anderson
Hi Ilia,

The default admin widget looks for id_0 and id_1, but if you use a custom 
widget, that is responsible for looking for its own value (like 
publish_time_1). You could check out DateTimePicker's source code to see 
what it's actually doing.

Thanks,
Collin

On Sunday, November 1, 2015 at 3:04:28 PM UTC+1, Ilia wrote:
>
> I'm trying to replace the standard AdminSplitDateTime widget in my admin 
> site for better functionality (basically I want to display only 'available' 
> dates in my calender which I couldn't find how to do with the default 
> picker). I decided to use the bootstrap3_datetime widget.
>
> After overriding my field to use the new widget, it doesn't seem to be 
> transferred into the 'clean' method (isn't in self.cleaned_data) for 
> validation.
>
> *models.py*
>
> publish_time = models.DateTimeField('Date to publish')
>
> *admin.py*
>
> class MyForm(forms.ModelForm):
>
> def __init__(self, *args, **kwargs):
> super(MyForm, self).__init__(*args, **kwargs)
> bad_dates = []
> #populating bad_dates with application logic
>
> def clean(self):
>
> # This will always return None when using the new widget.
> # When working with the default widget, I have the correct value.
> publish_time = self.cleaned_data.get('publish_time', None)
>
>
> publish_time = forms.DateTimeField(widget=DateTimePicker(options=
> {"format": "DD-MM- HH:mm",
>  "startDate": timezone.now().strftime('%Y-%m-%d'),
>  "disabledDates": bad_dates,
>  })
>
> class MyModelAdmin(admin.ModelAdmin):
> form = MyForm
>
> admin.site.register(MyModel, MyModelAdmin)
>
> HTML-wise, the widget works well and the text field is populated with the 
> correct date (and with the 'bad_dates' disabled). The problem is that it 
> seems it isn't saved on the form.
>
> I also tried initializing the widget in the init method by doing:
>
> self.fields['publish_time'].widget = DateTimePicker(options=...)
>
> But the result was the same.
>
> I've analysed the POST request that is sent using each of the widgets. In 
> the default admin widget, I see that it generates two fields: 
> "publish_time_0" (for date) and "publish_time_1" (for time). In the 
> bootstrap3 widget, only a single "publish_time" field is sent.
>
> I'm assuming that the admin site understands that the field is a 
> DateTimeField (from models), looks for id_0 and id_1 and that's why it 
> fails. Does that make sense? Is there anyway around it?
>
> Thanks a lot!
> Ilia
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/60cd4c0a-3220-46f7-8527-2230f291432c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: mssql databASE CONNECTION to Django

2015-11-05 Thread Collin Anderson
Hello,

I'd recommend using django 1.7 until mssql gets compatible with django 1.8.

Thanks,
Collin

On Friday, October 30, 2015 at 3:31:35 PM UTC+1, Sid wrote:
>
> sorry tim I know I am asking a dumb question...can you please tell me what 
> is the best way to make it work please if possibe...because I am struck 
> form last 2 days
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/111d7267-3597-4bdb-8bb9-20e3eb13879c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Locking / serializing access to one element in database

2015-11-05 Thread Collin Anderson
Hi Carsten,

If you're just updating one field, this _might_ work for you:

try:
TestMonthModel.objects.create(jahr=Jahr, monat=Monat)  # create() uses 
force_insert.
except IntegrityError:
pass # It already exists. No Problem.
# ... calculate some things.
TestMonthModel.objects.filter(jahr=Jahr, monat=Monat).update(value=new_value
)

Collin

On Wednesday, October 28, 2015 at 8:50:09 PM UTC+1, Carsten Fuchs wrote:
>
> Hi Collin, hi all, 
>
> Am 27.10.2015 um 19:56 schrieb Collin Anderson: 
> > Yes, an exception will be raised. 
>
> Thinking further about this, all we need is a method that gives us an 
> exception if we 
> accidentally create a second object when in fact only one is wanted. Your 
> suggestion 
> with manually dealing with the PKs and using .save(force_insert=True) is 
> one method to 
> achieve that, another one that works well for me is using an 
> (application-specific) 
>
>  unique_together = (year, month) 
>
> constraint, which achieves the desired result (guarantee uniqueness where 
> required, 
> raise an exception otherwise) without having to manually deal with PKs. 
>
> Alas, I wonder how to proceed to complete the solution. As I find it 
> simpler to deal 
> with the above mentioned unique_together rather than with coming up with a 
> PK based 
> solution, I refer to my original code from [1], which was: 
>
>
>  try: 
>  mm = TestMonthModel.objects.select_for_update().get(jahr=Jahr, 
> monat=Monat) 
>  except TestMonthModel.DoesNotExist: 
>  mm = TestMonthModel(jahr=Jahr, monat=Monat) 
>
>  # A *long* computation, eventually setting fields in mm and save: 
>
>  mm.value = 123 
>  mm.save() 
>
>
> Combining everything from this thread, this could be changed into this 
> code 
> (pseudo-code, not tested): 
>
>
>  while True: 
>  try: 
>  mm = 
> TestMonthModel.objects.select_for_update().get(jahr=Jahr, monat=Monat) 
>  break   # Got what we wanted! 
>  except TestMonthModel.DoesNotExist: 
>  try: 
> # Create the expected but missing instance. 
>  # No matter if the following succeeds normally or throws 
>  # an Integrity error, thereafter just restart the loop. 
>  TestMonthModel(jahr=Jahr, monat=Monat).save() 
>  except IntegrityError: 
>  pass 
>
>  # A *long* computation, eventually setting fields in mm and save: 
>
>  mm.value = 123 
>  mm.save() 
>
>
> Afaics, this solves the problem, but it also feels quite awkward and I 
> wonder if there 
> is a more elegant solution. 
>
> Comments? Does this sound reasonable at all? 
>
> Best regards, 
> Carsten 
>
> [1] https://groups.google.com/forum/#!topic/django-users/SOX5Vjedy_s 
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9351c121-9e4a-428d-8d70-e0563af99d97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [django_tables2] Expected table or queryset, not 'str'.

2015-11-05 Thread Collin Anderson
Hi,

Do you to post your traceback if you're still getting this error?

Thanks,
Collin

On Wednesday, October 28, 2015 at 2:17:28 PM UTC+1, Leutrim Osmani wrote:
>
> Can you please tell me how did you fixed this error ?
>
> On Monday, April 29, 2013 at 9:21:29 AM UTC+2, binith a k wrote:
>>
>> You were correct, it was indeed a version problem.
>> I was using latest django-tables2 in my new python virtual env and I had 
>> an older version (of django-tables2) installed as default, and the 
>> PYTHONPATH environment variable was pointing to the older version.
>>
>> Problem solved, thanks for the time
>>
>> thanks
>> -binith
>>
>> On Friday, 26 April 2013 07:25:35 UTC-7, Binith Babu wrote:
>>>
>>> I am sorry I coud not find a solution in this thread
>>>
>>> Did you mean I am using an older version of django tables2 ?
>>> In that case I am not, I am using the latest version installed with pip.
>>> May be its my mistake, I am still trying to figure whether I am doing 
>>> something wrong.
>>> WIll post back if I find something.
>>>
>>> Thanks
>>> binith
>>>
>>>
>>>
>>> On Friday, 26 April 2013 06:53:06 UTC-7, Tom Evans wrote:

 On Fri, Apr 26, 2013 at 2:30 PM, Binith Babu  wrote: 
 > 
 > I got the same error today, anybody know a solution? 
 > 

 Apart from the solution I already posted to the list in this thread? 

 Cheers 

 Tom 

>>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3f6afa29-5c9e-4dac-ad5d-a4c29824676a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Standalone Project using django ORM

2015-11-05 Thread Collin Anderson
Hi,

It looks like you stack trace is somehow getting cut off.

My guess is it's trying to import something that either doesn't exist or 
has a syntax error.

Collin

On Wednesday, October 28, 2015 at 12:39:06 AM UTC+1, ADEWALE ADISA wrote:
>
> The screen shot is attached. There is no error message but the trace. But 
> the program seem stop at django.setup(). Though it ran smoothly in django 
> 1.50
> On Oct 28, 2015 12:27 AM, "Dheerendra Rathor"  > wrote:
>
>> Is this the full stacktrace? Looks like error message is missing in 
>> stacktrace. 
>>
>> On Wed, 28 Oct 2015 at 04:05 ADEWALE ADISA > > wrote:
>>
>>> Hello;
>>> I have being having issues trying to use django orm in my application. 
>>> This issues occur when using django 1.85. The application run perfectly 
>>> well on django 1.50. Bellow are the snippet :
>>>
>>> Model.py:
>>> from django.db import models
>>>
>>> class Person(models.Model):
>>> name = models.CharField(max_length=100)
>>> email = models.CharField(max_length=100)
>>> birthdate = models.DateField()
>>> class Meta:
>>> app_label = 'runnable'
>>> 
>>> def __unicode__(self):
>>> return u'%d: %s' % (self.id, self.name)
>>>
>>> app.py:
>>>
>>> import sys
>>> from os import path
>>> import collections
>>> import datetime
>>> sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..'
>>> )))
>>>
>>> from django.core.management import call_command
>>> from django.conf import settings
>>>
>>> #print(sys.path)
>>> if not settings.configured:
>>> settings.configure(
>>>DEBUG=True,
>>> DATABASES={
>>> 'default': {
>>> # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 
>>> 'oracle'.
>>> 'ENGINE': 'django.db.backends.sqlite3',
>>> # Or path to database file if using sqlite3.
>>> 'NAME': ':memory:',
>>> }
>>> },
>>> INSTALLED_APPS=("runnable", )
>>> 
>>> )
>>>
>>> import django
>>> django.setup()
>>> #call_command('syncdb')
>>> call_command('makemigrations')
>>> call_command('migrate')
>>> call_command('inspectdb')
>>> from models import Person
>>> print("PERSON: "+ Person)
>>>
>>> Console msg:
>>> p.py", line 28, in 
>>> django.setup()
>>>   File 
>>> "/data/data/com.hipipal.qpy3/files/lib/python3.2/site-packages/django/__init__.py",
>>>  
>>> line 18, in setup
>>> apps.populate(settings.INSTALLED_APPS)
>>>   File 
>>> "/data/data/com.hipipal.qpy3/files/lib/python3.2/site-packages/django/apps/registry.py",
>>>  
>>> line 108, in populate
>>> app_config.import_models(all_models)
>>>   File 
>>> "/data/data/com.hipipal.qpy3/files/lib/python3.2/site-packages/django/apps/config.py",
>>>  
>>> line 198, in import_models
>>> self.models_module = import_module(models_module_name)
>>>   File 
>>> "/data/data/com.hipipal.qpy3/files/lib/python3.2/python32.zip/importlib/__init__.py",
>>>  
>>> line 124, in import_module
>>>
>>> Note:
>>> The application run successfully with django 1.50  by uncomment syncdb 
>>> and comment out migration, make migrations.
>>>
>>> Thanks.
>>>
>>> -- 
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/CAMGzuy9BSMrgqw8uMgp3kd9eBu5fTdF4DCB9%3Di-8r6EmZmN-WA%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...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAByqUgjWYn%3DtfSeA-EBrzeur2_jodiPysZUS%3Dor%2BFeCFpKhbwg%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@googlegro

Re: Safe tag is working differently for different view.

2015-11-05 Thread Collin Anderson
Hello,

Are you sure they're using the same template? (If you change something does 
it actually affect both views?)

Is one of the views using mark_safe?

Collin

On Tuesday, October 27, 2015 at 9:29:02 PM UTC+1, sonu kumar wrote:
>
> I am having two views both are extending from same base.html and both of 
> them have loaded same template tags, but one is escaping string using safe 
> and other is not what could be 
> Code 
>
> view 1
>
> {% extends 'base.html' %}
> {% load inplace_edit mezzanine_tags rating_tags keyword_tags comment_tags 
> nano_tags staticfiles %}
>
> ...
>
> {% comments_for object %}
>
> ...
>
> view 2
>
> {% extends "base.html" %}
>
> {% load inplace_edit mezzanine_tags comment_tags keyword_tags nano_tags i18n 
> future staticfiles %}
>
> ...
>
> {% comments_for blog_post %}
>
> ...
>
>
> view3 (comment.html)
>
> {% load i18n mezzanine_tags comment_tags  nano_tags future %}
>
> ...
>
> {{ comment.comment|safe  }}
>
> ...
>
>
> As we can see both view 1 and 2 are using same function so it would be using 
> same template but in view2 safe is working and in view1 it's not working.
>
>
> What could be the reason for this ?
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ba60efb5-36be-492a-b9f0-e1007de500f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Models Joining and Normalising

2015-10-28 Thread Collin Anderson
Hello,

I'd personally keep it all in one model for as long as possible. It will 
really simplify queries and it should make your code a lot cleaner. Wait 
til you have some actual performance problems before splitting the models 
up.

Collin

On Wednesday, October 14, 2015 at 12:11:55 PM UTC-4, Yunti wrote:
>
> I'm still relatively new to Django and now working on a project that has 
> much more complex models than I've used before.  
>
> The question is about when is it best to separate out large models into 
> separate models (and the impact caused by joining the smaller models 
> together and also keeping data normalised).  
>
> I'm trying to model magazine subscriptions, which are available from 
> different suppliers - the costs vary slightly per region (due to delivery 
> costs) and the available subscriptions vary slightly dependent on payment 
> type (direct debit, card, cheque etc...). 
>
> The subscriptions have a lot of different fields for each subscriptions so 
> I'm not clear on how best to represent this in django - one large model or 
> split into smaller models.
>
> Firstly,  each supplier will have multiple magazines - to keep the data 
> normalised should the suppliers be kept in a separate table/model separate 
> to the subscriptions table? How will this impact performance when having to 
> join the data back together when querying a list of subscriptions. 
> (e.g. similarly for payment types of which there are only 4 should these 
> be pulled out into a separate table? and regions)
>
> There will be a form field for: 
> supplier
> payment type,
> region,
> should a separate model be made for these 3 fields to ease with making the 
> form and how should that tie into the above tables (if they should be 
> separated? Should I make e.g. an Input model class with ForeignKeys to each 
> of the separate tables?). 
>
> Thanks.  
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7d7cd8ae-ebd9-43f7-aa8b-ba967dc93795%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Flakey tests and django.db.utils.InterfaceError: connection already closed

2015-10-28 Thread Collin Anderson
Hello,

Here are some questions that might help debugging this:

Do other tests that use the database run ok?

If you run _only_ this test, is it still a problem?

Are you using threads at all?

Is there an exception that's being silenced somewhere else?

Collin


On Tuesday, October 27, 2015 at 9:14:13 AM UTC-4, Christopher R. wrote:
>
> Have you been able to fix the problem? I am encountering the same issue on 
> both Django 1.8.4 and 1.8.5.
>
> Any help would be appreciated.
>
> On Thursday, October 8, 2015 at 3:38:16 PM UTC+1, thinkwell wrote:
>>
>> I could use some assistance in troubleshooting a psycopg2.InterfaceError 
>> problem that has erratic behavior. Here is the test module 
>>  suite that I'm running to test these 
>> models , and in this state all the tests 
>> in the module pass. However, it's extremely easy to trigger a 
>> psycopg2.InterfaceError, although not relating to the lines changed. For 
>> example, if I change:
>>
>> class TestSilly(SimpleTestCase): 
>>   
>> def test_is_not_false(self): 
>> self.assertTrue(False is not True)
>>
>>
>> to 
>>
>> class TestSilly(TestCase): 
>>   
>> def test_is_not_false(self): 
>> self.assertTrue(False is not True)
>>
>>   
>>
>> Then this error is raised, but referencing TestPolicyModel instead of 
>> TestSilly!
>>
>> ==
>> ERROR: test_toggle_autofix (accounts.tests.test_models.TestPolicyModel)
>> --
>> Traceback (most recent call last):
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", 
>> line 137, in _cursor
>> return self.create_cursor()
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py"
>> , line 212, in create_cursor
>> cursor = self.connection.cursor()
>> psycopg2.InterfaceError: connection already closed
>>
>> The above exception was the direct cause of the following exception:
>>
>> Traceback (most recent call last):
>>   File "apps/accounts/tests/test_models.py", line 174, in 
>> test_toggle_autofix
>> p = Policy.objects.first()
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/models/manager.py", 
>> line 127, in manager_method
>> return getattr(self.get_queryset(), name)(*args, **kwargs)
>>   File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py"
>> , line 490, in first
>> objects = list((self if self.ordered else self.order_by('pk'))[:1])
>>   File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py"
>> , line 162, in __iter__
>> self._fetch_all()
>>   File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py"
>> , line 965, in _fetch_all
>> self._result_cache = list(self.iterator())
>>   File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py"
>> , line 238, in iterator
>> results = compiler.execute_sql()
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/models/sql/compiler.py"
>> , line 838, in execute_sql
>> cursor = self.connection.cursor()
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", 
>> line 164, in cursor
>> cursor = self.make_cursor(self._cursor())
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", 
>> line 137, in _cursor
>> return self.create_cursor()
>>   File "/usr/local/lib/python3.4/dist-packages/django/db/utils.py", line 
>> 97, in __exit__
>> six.reraise(dj_exc_type, dj_exc_value, traceback)
>>   File "/usr/local/lib/python3.4/dist-packages/django/utils/six.py", 
>> line 658, in reraise
>> raise value.with_traceback(tb)
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", 
>> line 137, in _cursor
>> return self.create_cursor()
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py"
>> , line 212, in create_cursor
>> cursor = self.connection.cursor()
>> django.db.utils.InterfaceError: connection already closed
>>
>>
>> For another example, if I change 
>>
>> TestPolicyModel(TestCase)
>>
>>
>> to
>>
>> TestPolicyModel(SimpleTestCase)
>>
>>
>> then, I get the following error regarding TestRedwoodModel
>>
>> ==
>> ERROR: setUpClass (accounts.tests.test_models.TestRedwoodModel)
>> --
>> Traceback (most recent call last):
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", 
>> line 137, in _cursor
>> return self.create_cursor()
>>   File 
>> "/usr/local/lib/python3.4/dist-packages/django/db/backends/postgresql_psycopg2/base.py"
>> , line 212, in create_cursor
>> cursor = self.connection.cursor()
>> psycopg2.InterfaceError: connection already 

Re: Polymorphic class and geomodels?

2015-10-28 Thread Collin Anderson
Hello,

Are you trying to combine multiple models into one, like this?

class PolyModel(pdmpunto, pdmtransetto, pdmarea):
pass

You could also try asking on the geodjango list: 
http://groups.google.com/group/geodjango

Collin

On Monday, October 26, 2015 at 7:18:24 AM UTC-4, Luca Moiana wrote:
>
> Hi, working on my first django app, and run into a problem.
>
> I tend to create geodjango objects, and add all data from external tables 
> with pk.
>
> Then I want to have different geometries 8points, lines, polygons) into a 
> unique polymorphic class, can I do that?
>
> I have an error that I'll document later, and I'm trying to figure out 
> what to do.
>
> Here is the model:
> import datetime
>
> from django.db import models
> from django.contrib.gis.db import models as geomodels
> from django.utils import timezone
> from django.forms import ModelForm
> from polymorphic import PolymorphicModel
>
> # Geometria linea da monitorare
> class geolinea(geomodels.Model):
> progetto = models.CharField(max_length=14, primary_key=True)
> geom = geomodels.MultiLineStringField()
> objects = geomodels.GeoManager()
> def __str__(self):
> return '%s' % (self.progetto)
> # Oggetto Progetto soggetto a PMA
> class linea(models.Model):
> progetto = models.ForeignKey(geolinea)
> nome = models.CharField(max_length=200)
> TENSIONE = (
> ('132', '132kV'),
> ('150', '150kV'),
> ('220', '220kV'),
> ('380', '380kV'),
> )
> tensione = models.CharField(max_length=5,
> choices=TENSIONE)
> def __str__(self):
> return '%s' % (self.nome)
>
> # Geometria dei pdm
> class pdmpunto(geomodels.Model):
> linea = models.ForeignKey(linea)
> numero = models.CharField(max_length=3)
> geom = geomodels.PointField()
> objects = geomodels.GeoManager()
>
> class pdmtransetto(geomodels.Model):
> linea = models.ForeignKey(linea)
> numero = models.CharField(max_length=3)
> geom = geomodels.LineStringField()
> objects = geomodels.GeoManager()
>
> class pdmarea(geomodels.Model):
> linea = models.ForeignKey(linea)
> numero = models.CharField(max_length=3)
> geom = geomodels.PolygonField()
> objects = geomodels.GeoManager()
>
> class pdm(PolymorphicModel):
> numero = models.CharField(max_length=14, primary_key=True)
> class punto(pdm):
> rifpunto = models.ForeignKey(pdmpunto)
> class transetto(pdm):
> riftransetto = models.ForeignKey(pdmtransetto)
> class area(pdm):
> rifarea = models.ForeignKey(pdmarea)
>
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/45f813d4-c476-4cc5-a299-03fb10edd6b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding gif file to existing project

2015-10-27 Thread Collin Anderson
Hi Gary,

This sounds like an issue with Ninja-IDE. You could try asking on their 
mailing list: http://groups.google.com/group/ninja-ide/topics

Thanks,
Collin

On Sunday, October 25, 2015 at 10:51:13 PM UTC-4, Gary Roach wrote:
>
> Django 1.8 
> Python 3.4 
> Debian 8 (jessie) with kde desktop 
> Postresql 9.4 
> Apache2 
> venv environment setup 
> Ninja-IDE 
>
> The problem is that I am having trouble getting the image.gif file in 
> the project to show up in the IDE directory. The project tree is as 
> follows: 
>
> . 
> ├── archive 
> │   ├── archive 
> │   │   ├── __init__.py 
> │   │   ├── __pycache__ 
> │   │   │   ├── __init__.cpython-34.pyc 
> │   │   │   ├── settings.cpython-34.pyc 
> │   │   │   ├── urls.cpython-34.pyc 
> │   │   │   └── wsgi.cpython-34.pyc 
> │   │   ├── settings.py 
> │   │   ├── urls.py 
> │   │   └── wsgi.py 
> │   ├── archive.nja 
> │   ├── db.sqlite3 
> │   ├── home 
> │   │   ├── admin.py 
> │   │   ├── __init__.py 
> │   │   ├── migrations 
> │   │   │   ├── __init__.py 
> │   │   │   └── __pycache__ 
> │   │   │   └── __init__.cpython-34.pyc 
> │   │   ├── models.py 
> │   │   ├── __pycache__ 
> │   │   │   ├── admin.cpython-34.pyc 
> │   │   │   ├── __init__.cpython-34.pyc 
> │   │   │   ├── models.cpython-34.pyc 
> │   │   │   └── views.cpython-34.pyc 
> │   │   ├── tests.py 
> │   │   └── views.py 
> │   ├── __init__.py 
> │   ├── main 
> │   │   ├── admin.py 
> │   │   ├── __init__.py 
> │   │   ├── migrations 
> │   │   │   ├── 0001_initial.py 
> │   │   │   ├── 0002_auto_20151019_1147.py 
> │   │   │   ├── 0003_auto_20151021_1441.py 
> │   │   │   ├── __init__.py 
> │   │   │   └── __pycache__ 
> │   │   │   ├── 0001_initial.cpython-34.pyc 
> │   │   │   ├── 0002_auto_20151019_1147.cpython-34.pyc 
> │   │   │   ├── 0003_auto_20151021_1441.cpython-34.pyc 
> │   │   │   └── __init__.cpython-34.pyc 
> │   │   ├── models.py 
> │   │   ├── __pycache__ 
> │   │   │   ├── admin.cpython-34.pyc 
> │   │   │   ├── __init__.cpython-34.pyc 
> │   │   │   └── models.cpython-34.pyc 
> │   │   ├── tests.py 
> │   │   └── views.py 
> │   ├── manage.py 
> │   ├── static 
> │   │   ├── home 
> │   │   │   ├── images 
> │   │   │   │   ├── django.gif 
> │   │   │   │   └── __init__.py 
> │   │   │   ├── __init__.py 
> │   │   │   └── style.css 
> │   │   └── __init__.py 
> │   └── templates 
> │   ├── admin 
> │   │   ├── base_site.html 
> │   │   └── __init__.py 
> │   ├── home 
> │   │   ├── index.html 
> │   │   └── __init__.py 
> │   └── __init__.py 
>
> You will notice that there is a django.gif file under static / home / 
> images. Unfortunately, this file does not show up in the IDE's tree. 
> I can't seem to figure out why. Below is the settings.py file for the 
> project. Have I done something wrong here. 
>
> _ 
>
> # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
> import os 
>
> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 
>
>
> # Quick-start development settings - unsuitable for production 
> # See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ 
>
> # SECURITY WARNING: keep the secret key used in production secret! 
> SECRET_KEY = '$ey(n0ld$2v7x*4b+&a2n7!zt#+ub519+km9n=_4yz2f2kd&s5' 
>
> # SECURITY WARNING: don't run with debug turned on in production! 
> DEBUG = True 
>
> ALLOWED_HOSTS = [] 
>
>
> # Application definition 
>
> INSTALLED_APPS = ( 
>  'django.contrib.admin', 
>  'django.contrib.auth', 
>  'django.contrib.contenttypes', 
>  'django.contrib.sessions', 
>  'django.contrib.messages', 
>  'django.contrib.staticfiles', 
>  'main', 
>  'home', 
> ) 
>
> MIDDLEWARE_CLASSES = ( 
>  'django.contrib.sessions.middleware.SessionMiddleware', 
>  'django.middleware.common.CommonMiddleware', 
>  'django.middleware.csrf.CsrfViewMiddleware', 
>  'django.contrib.auth.middleware.AuthenticationMiddleware', 
>  'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 
>  'django.contrib.messages.middleware.MessageMiddleware', 
>  'django.middleware.clickjacking.XFrameOptionsMiddleware', 
>  'django.middleware.security.SecurityMiddleware', 
> ) 
>
> ROOT_URLCONF = 'archive.urls' 
>
> TEMPLATES = [ 
>  { 
>  'BACKEND': 'django.template.backends.django.DjangoTemplates', 
>  'DIRS': [os.path.join(BASE_DIR, 'templates')], 
>  'APP_DIRS': True, 
>  'OPTIONS': { 
>  'context_processors': [ 
>  'django.template.context_processors.debug', 
>  'django.template.context_processors.request', 
>  'django.contrib.auth.context_processors.auth', 
>  'django.contrib.messages.context_processors.messages', 
>  ], 
>  }, 
>  }, 
> ] 
>
> WSGI_APPLICATION = 'archive.wsgi.application' 
>
>
> # Database 
> # https://docs.djangoproject.com/en/1.8

Re: Locking / serializing access to one element in database

2015-10-27 Thread Collin Anderson
Yes, an exception will be raised. As an example, Django uses force_insert 
when creating sessions:

https://github.com/django/django/blob/32ef48aa562e6aaee9983f5d0f1c60f02fd555fb/django/contrib/sessions/backends/db.py#L86

On Saturday, October 24, 2015 at 2:36:15 PM UTC-4, Joakim Hove wrote:
>
> Hi Collin;
>
> thank you for your suggestion:
>
> [...] if the thread thinks that the object is new, it could try using 
>> .save(force_insert=True). 
>>
>
> I have read to read the force_insert documentation without understanding 
> 100%. Assume threads t1 and t2 are racing to create the first element with 
> this primary key, and that t1 wins the race. Then when t2 issues:
> 
> save( force_insert = True )
>
> will an exception be raised?
>
>  
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/249303c1-2a39-41a0-8ab9-0d6e4a1bf9fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: makemigrations and language_code

2015-10-27 Thread Collin Anderson
Hi,

is libapp using ugettext_lazy? That's what the admin app is using.

Collin

On Thursday, October 22, 2015 at 2:53:53 AM UTC-4, Hugo Osvaldo Barrera 
wrote:
>
>  
> On Tue, Oct 20, 2015, at 10:39, Aron Podrigal wrote:
>
> Simply run 
>
> ./manage.py makemigrations myapp 
>
>  
> That will avoid running for all your installed apps.
>
>  
> That's merely a workaround, but it still doesn't solve the problem. 
> Mainly, other users of libapp will still encounter the same issue.
>  
> I'm curious as to how the admin app avoid this particular issue.
>  
>
>  
> On Monday, October 19, 2015 at 12:58:23 AM UTC-4, Hugo Osvaldo Barrera 
> wrote:
>
> I'm having a rather confusing scenario regarding makemigrations and 
> language_code: 
>  
> * I've an app (let's call it myapp) which I'm developing. 
> * myapp relies on the another app (let's call it libapp). 
> * myapp has language_code set to "es-ar". 
> * libapp was developed separately, and has been installed via pip. 
>  
> While developing myapp, whenever I run "makemigrations" a migrations is 
> also created for libapp. The migrations updates all the verbose_name and 
> help_text fields and nothing else. I don't want this, especially since 
> it creates a conflict in the migration graph when I later upgrade 
> libapp. 
>  
> How can I have makemigrations *ignore* the language_code? 
>  
> Also, why does makemigrations create this migration for libapp, but not 
> an equivalent one for django.contrib.admin? 
> I tried looking at things like the admin to see how they avoid this, and 
> found no clues. 
>  
> Thanks, 
>  
> -- 
> Hugo Osvaldo Barrera 
>
>  
> --
> Hugo Osvaldo Barrera
>  
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c7dc176c-7df4-4f7a-acf6-75b4a3d29ad4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic Formset Radiobutton Issue

2015-10-24 Thread Collin Anderson
Hello,

That formset jQuery script it quite ancient (2009). You could try using 
jQuery 1.2.6 and see if it works correctly with that version.

Collin

On Friday, October 23, 2015 at 8:54:49 AM UTC-4, Jur Remeijn wrote:
>
> So I'm using a dynamic formset within django: 
> https://github.com/elo80ka/django-dynamic-formset
> I'm using it to render a page with a form (say, a pizza) and a formset 
> (say, a set of toppings). Because the number of toppings isn't determined, 
> I want to use a dynamical formset. 
> Right now, I have the page display one instance of topping form, with a 
> button to add another instance, which is added with the javascript found in 
> the github repo (and as a attachment).
> Only I have a problem: When I fill in the form for one topping, and then 
> add another topping, all the radiobuttons get reset so the data from the 
> first topping is lost. 
>
> Does anyone see what goes wrong here? This is my code, simplified (I 
> actually have a lot more fields for the form and subset, all choicefields 
> needing radiobuttons, so this is quite a big issue for me). 
>
> models.py:
> *class Pizza(models.Model):*
> *name= models.CharField(max_length=55)*
> *pricerange=models.CharField(max_length=55, 
> choices=PRICERANGE_CHOICES)*
>
> *class Topping(models.Model):*
> *pizza = models.ForeignKey(Pizza)*
> *number = models.IntegerField(null=True, blank=True)*
> *name=models.CharField(max_length=55, choices=TOPPINGNAME_CHOICES)*
>
> forms.py:
> class PizzaForm(forms.ModelForm):
>
>   class Meta:
> model = Pizza
> fields = ['name', 'pricerange']
> 
>   pricerange= 
> forms.ChoiceField(required=True,widget=forms.RadioSelect(),choices=PRICERANGE_CHOICES)
>
> class ToppingForm(forms.ModelForm):
>   class Meta:
> model = Topping
> fields = ['number', 'name'
> *]*
>   
>   number = forms.IntegerField(required=True)
>   name = 
> forms.ChoiceField(required=True,widget=forms.RadioSelect(),choices=TOPPINGNAME_CHOICES)
>
> ToppingFormset = formset_factory(ToppingForm, max_num=8)
>
> form.html:
> * src="/static/pizza/jquery-1.11.3.min.js">*
> * src="/static/pizza/jquery.formset.js">*
> **
> *$(function() {*
> *$('.ToppingForm').formset();*
> *})*
> **
>
>
>
>
> *.add-row {padding-left:18px;
> background:url(/static/arts/images/add.png) no-repeat left center;}
> .delete-row {display:block;margin:6px 0 0 0;
> padding-left:18px;background:url(/static/arts/images/delete.png) 
> no-repeat left center;}.dynamic-form { padding: 5px 15px; 
> }   {% csrf_token %} {{ 
> form.non_field_errors }}{{ form.name  }}
> {{ form.pricerange}}  {% for form in 
> formset.forms %}  
>  {{ 
> form.name.label_tag }} {{ form.name.errors }}  {% for radio 
> in form.name  %} {{ radio }} {% endfor %}  
> {{ form.number.errors }}{{ 
> form.number}}  {% endfor %}  {{ formset.management_form 
> }} *
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4881d596-f1f5-4182-8124-7c5ff2e0e5fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Locking / serializing access to one element in database

2015-10-24 Thread Collin Anderson
Hi Carsten,

Something that might help: depending on how your unique keys are set up, if 
the thread thinks that the object is new, it could try using 
.save(force_insert=True). That way it won't overwrite a different object 
with the same PK.

Thanks,
Collin

On Thursday, October 22, 2015 at 9:56:36 AM UTC-4, Carsten Fuchs wrote:
>
> Am 22.10.2015 um 01:16 schrieb Simon Charette: 
> > I would suggest you use select_for_update() 
> > <
> https://docs.djangoproject.com/en/1.8/ref/models/querysets/#select-for-update>
>  
> in a 
> > transaction. 
>
> This only covers the case where the object with the given ID already 
> exists, doesn't it? 
>
> That is, if a new object is created in the except-clause, concurrent 
> threads might 
> create a new object each, whereas it would presumably be expected that 
> new_text is 
> (twice) added to a single common instance. 
>
> As I had the quasi exact same question a while ago (see 
> https://groups.google.com/forum/#!topic/django-users/SOX5Vjedy_s) but 
> never got a reply, 
> I (too) am wondering how the new-object case in the except-clause could be 
> handled? 
>
> Best regards, 
> Carsten 
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/46fead13-f0b6-4321-b184-1bb51ed3a294%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Complex form in modelform

2015-10-24 Thread Collin Anderson
Hi,

For starters, here's an example of a formset for multiple images:
http://stackoverflow.com/questions/32889199/how-to-upload-multiple-images-using-modelformset-django

Collin

On Monday, October 19, 2015 at 4:56:18 PM UTC-4, Arnab Banerji wrote:
>
> Hi - I am trying to create a form from a model, say M with the following:
>
> (1) a certain field FOO is a text field which would be constructed in 
> views.py by concatenating a dynamic set of rows (so I need a jQuery plugin 
> for that).
>
> (2) multiple images can be tied to the model M, and I have a ForeignKey in 
> the image model that maps to M - I need a jQuery plugin for that too so 
> that users can add images dynamically.
>
> (3) If a user gave a name already in use, the form goes into "edit" mode 
> for the already existing model (modelchoiceform with validation to the 
> rescue?)
>
> Any good examples of the above scenarios? Or a form handling API?
>
> Thanks a ton!
> -AB
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2077f73a-b3b4-4830-bf70-adb7da60ac60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django: Relation does not exist in Postgresql

2015-09-04 Thread Anderson Resende
You need to create that tables at your database. 
Please run: 
python manage.py makemigrations
python manage.py migrate

Try it! 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8c1a607a-9dff-49b7-8abc-d9b6ac5d03cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Http post and csrf error

2015-03-31 Thread Anderson Resende

In your template put  in your form:

{% csrf_token %}

example:


  {% csrf_token %}



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9ffa27a1-ee3b-4c95-871d-82b17cd9989d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problem at server startup

2015-03-28 Thread Anderson Resende
Put this code on first line in your files.py:

# -*- coding: utf-8 -*-


Maybe work!



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/56961c03-87af-4f8d-8c18-1080b88d446c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Strange deployment problem

2015-03-28 Thread Anderson Resende

I don't used mysql,but in postgres for you write in a database your user db 
needs permission to write.
Check that!

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b0eba252-8c3e-4b51-ab38-ea7f04df3a69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Global access to request.user

2015-03-27 Thread Anderson Resende
Other way is use sessions!
Django provide session midleware.
You can get the session dict out of the view!


Sorry my english, I am a Brazilian guy! 

>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/892e4ff2-a85b-49a2-a13d-449319299f1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Global access to request.user

2015-03-27 Thread Anderson Resende

Maybe a global state? Yes! 

https://docs.djangoproject.com/en/1.7/topics/http/middleware/#init

I never did that, but you can try!



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6481f72f-aac4-4127-b496-b85c4dc1d987%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Global access to request.user

2015-03-26 Thread Anderson Resende
You can use middlewares!!! It is a way...


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2c55f576-7012-49a2-bd53-a8e5fdc4754a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to access manager from a model instance?

2015-03-26 Thread Anderson Resende
Can you give a example? be more especific, post some code.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/48f6a3e4-f0f7-4ab9-8ad4-0685b6cf98d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Max_length of EmailField in django.contrib.auth.models.User

2015-03-22 Thread Anderson Resende
I will give you one more complete example:
Custom a User is not easy you need to do many things:

In that link django-docs explain all for you and there is an example with 
email field.

https://docs.djangoproject.com/en/1.7/topics/auth/customizing/#a-full-example


My tip is: In the docs there is many other fields like birth_date that you 
can remove.
Second, In docs the email field has used with username, you can create your 
own username field and in 

USERNAME_FIELD = 'email' change for USERNAME_FIELD = 'myusername'


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/60403108-2619-401c-b560-a5539733a0ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Max_length of EmailField in django.contrib.auth.models.User

2015-03-22 Thread Anderson Resende
You can inheriant of AbstractBaseUser and define your field:

from django.contrib.auth.models import AbstractBaseUser

class MyCustomUser(AbstractBaseUser):
 mail = models.EmailField(max_lenght=254)

REQUIRED_FIELDS = ['mail']
 # more code
 

Please sorry about my english, I'm a Brazilian guy rsrsrs

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7645be66-003f-4c41-840e-75844dc5008e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why is appearance of admin page so different between development and deployment servers?

2015-03-22 Thread Anderson Resende
Em production you need to run the command: python manage.py collectstatic 
and you need configure your production serve like "apache" to read the 
'static' folder in you root project.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6795cfc2-ff9b-43b2-9e02-a39ab6c1706e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Max_length of EmailField in django.contrib.auth.models.User

2015-03-22 Thread Anderson Resende
No, the user class uses 75. You need to change to 254.

models.EmailField(max_lenght=254)

>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bc103aeb-a048-42b1-9d0e-f17a4df4d4d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Python] Problem with arguments given

2015-03-14 Thread Anderson Resende
Change your method:

def ask_number(self,question,low,high):
response=None
while response not in range(low,high):
response=int(input(question))


change  self to class:
This way you can call the method directly from Hand.

@classmethod
def ask_number(class,question,low,high):
response=None
while response not in range(low,high):
response=int(input(question))




-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b9712dd0-03b2-4623-ae76-4f81055bd83b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.7.6 TypeError when applying migration with ForeignKey with default

2015-03-12 Thread Collin Anderson
Hi,

Maybe g() should return the id instead of the instance? That does seem a 
bit odd that it wouldn't accept an A() instance as the default.

Collin

On Wednesday, March 11, 2015 at 7:43:35 AM UTC-4, Krzysztof Ciebiera wrote:
>
> I have created a model A:
>
> def g():
> return A.objects.get(pk=1)
>
> class A(models.Model):
> a = models.IntegerField()
>
> ./manage.py makemigrations
> ./manage.py migrate
>
> then I've added some data:
>
> a = A(a=1)
> a.save()
>
> then I have created another model with a ForeignKey field with a default 
> set to g function (that really returns one instance od A) and I was trying 
> to migrate it:
>
> class B(models.Model):
> b = models.ForeignKey(A, default=g)
>
> ./manage.py makemigrations
> ...
> ./manage.py migrate
> 
>   File 
> ".../e/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
>  
> line 627, in get_db_prep_save
> prepared=False)
>   File 
> ".../e/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
>  
> line 907, in get_db_prep_value
> value = self.get_prep_value(value)
>   File 
> ".../p/e/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py",
>  
> line 915, in get_prep_value
> return int(value)
> TypeError: int() argument must be a string or a number, not 'A'
>
> Is it expected behaviour or a bug?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/877cc6a3-1b37-4b88-918b-a0f955f59c8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Testing Django: testing template at different time

2015-03-12 Thread Collin Anderson
Hi,

You could try using freezegun to run the test as if it were a certain time 
of day.
https://pypi.python.org/pypi/freezegun

Or, you could say something like:
if 9 <= datetime.datetime.now().hour < 17:
self.assertContains(response, "It's working time!") 
else:
self.assertContains(response, "Happy holiday!")

That way it will at least not fail (most of the time :).

Collin

On Wednesday, March 11, 2015 at 7:43:35 AM UTC-4, Zaki Akhmad wrote:
>
> Hello, 
>
> I'd like to write a test script for my django app. 
>
> Example, if within business hour, my django app will render: 
> "It's working time!" 
>
> And if not within business hour, my django app will render: 
> "Happy holiday!" 
>
> So the views, will check when the url is accessed. 
>
> How do I write the test script? 
> Following django docs here[1], I started to write my test code. 
>
> from django.test import Client, TestCase 
>
> class TestPage(TestCase): 
> def test_holiday(self): 
> response = self.client.get('/day/') 
> self.assertEqual(response.status_code, 200) 
> self.assertContains(response, "It's working time!") 
>
> This test code will success if I run within business hour. But If I 
> run it not within business hour, the test code will fail. 
>
> * How to write a better test code? 
> * How do I use mock/patch? 
> * How to write test code that will check the within and not within 
> business hour in one file that both will success whenever I run the 
> test code? 
>
> [1]
> https://docs.djangoproject.com/en/1.7/topics/testing/tools/#testing-responses 
>
> Thanks, 
>
> -- 
> Zaki Akhmad 
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3003d453-3d31-4fed-ab9a-eadd40fee8af%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Different user profile associated to a each user group

2015-03-12 Thread Collin Anderson
Hi,

I'd personally recommend re-using the same model and having a "type" field 
for whether it's corporate or private.

Otherwise, you'd need to do something like:

class Corporate(models.Model):
user = models.OneToOneField(User)

class Private(models.Model):
user = models.OneToOneField(User)

Then, you would need to try to query for the profile. Something like:
try:
corporate = request.user.corporate
except Corporate.DoesNotExist:
corporate = None

Collin

On Wednesday, March 11, 2015 at 3:50:31 AM UTC-4, elpaso wrote:
>
> Hi, 
>
> I've used custom user profiles in the past, but they were associated 
> to all users, now I need to associate a different custom profile for 
> each user group (for example: "corporate", "private"). 
>
> Any hint about the best approach? 
>
> -- 
> Alessandro Pasotti 
> w3:   www.itopen.it 
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/56237ed7-f3e2-4835-bfea-93226b17199e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django OperationalError

2015-03-12 Thread Collin Anderson
Hi,

Do you have the correct file path set to your sqlite3 database? Does it 
have proper permissions?

I found a similar issue here:
https://www.pythonanywhere.com/forums/topic/1814/

Collin

On Wednesday, March 11, 2015 at 2:04:45 AM UTC-4, Petar Pilipovic wrote:
>
> Hey Collin,
> I have done what have you told me, but I still have that error, I even 
> created data base on www.pythonanywhere.com, and amend mine setting.py 
> file to use that db.
> I have manually deleted database and done syncdb, migrate etc.
> Here are the output for syncdb <http://ur1.ca/jvzba>, and then I have 
> made mine superuser, this is the Operational Error <http://ur1.ca/jvzbq>.
> Question: Why is he reporting this template rendering error on line 40? 
> <http://ur1.ca/jvzbz>
> Tank you
> Best 
> Petar
>
> On Tue, Mar 10, 2015 at 6:49 PM, Petar Pilipovic  > wrote:
>
>> Heh, lol, Ok tax Collin I will do that. I was thinking that i need to 
>> delete mine migration from the terminal, but I will try that, tnx
>> 10.03.2015. 18.01, "Collin Anderson" > 
>> је написао/ла:
>>
>> Hi Petar,
>>>
>>> I'm actually not sure why you want to call sqlflush. If you're trying to 
>>> clear out the database, you may need to delete the migrations table 
>>> manually, but it just might be simpler to delete the either database and 
>>> re-create it, rather than the individual tables.
>>>
>>> Collin
>>>
>>> On Friday, March 6, 2015 at 11:24:19 PM UTC-5, Petar Pilipovic wrote:
>>>>
>>>> Hello Collin,
>>>> No the problem is, i have tried to drop mine migrations whit python 
>>>> manage sqlflush, then I have recreate the db whit 
>>>> python manage.py migrate.
>>>> Here this is the all operation whit python manage sqlflush, syncdb, 
>>>> migrate <http://ur1.ca/jv371>. I have notice that there was no 
>>>> migration to apply at the end, and the error is still there.
>>>> Is there something else I can do, or how can I approach this 
>>>> differently.
>>>> Best
>>>> Petar
>>>>
>>>> On Fri, Mar 6, 2015 at 11:21 PM, Collin Anderson  
>>>> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> The problem is that django_session doesn't exist in your database. 
>>>>> Either it was never created or it was created and then later deleted.
>>>>>
>>>>> Does running manage.py migrate re-create it?
>>>>>
>>>>> Collin
>>>>>
>>>>> On Monday, March 2, 2015 at 11:36:51 PM UTC-5, Petar Pilipovic wrote:
>>>>>>
>>>>>> Hello James, sorry for not uploading mine answer on this mater, I was 
>>>>>> busy whit something else this day, ok now back to mine Operational Error 
>>>>>> I 
>>>>>> have got.
>>>>>> I tried to google some solution to this problem had no luck, and I 
>>>>>> did what have you told me.
>>>>>> I heave done some 
>>>>>> python manage.py sqlflush
>>>>>>
>>>>>> and that has gave me this output: 
>>>>>>
>>>>>> (django17)04:20 ~/mineDjango$ python manage.py sqlflush BEGIN;DELETE 
>>>>>> FROM "django_admin_log";DELETE FROM "auth_permission";DELETE FROM 
>>>>>> "auth_group";DELETE FROM "auth_group_permissions";DELETE FROM 
>>>>>> "django_session";DELETE FROM "auth_user_groups";DELETE FROM 
>>>>>> "auth_user_user_permissions";DELETE FROM "account_emailaddress";
>>>>>> DELETE FROM "django_site";DELETE FROM "profiles_profile";DELETE FROM 
>>>>>> "auth_user";DELETE FROM "profiles_userstripe";DELETE FROM 
>>>>>> "account_emailconfirmation";DELETE FROM "django_content_type";COMMIT;
>>>>>>
>>>>>> Then I have done 
>>>>>> python manage.py syncdb python manage.py migrate
>>>>>>
>>>>>> Output of mine recreating tables are this:
>>>>>> (django17)04:20 ~/mineDjango$ python manage.py syncdbOperations to 
>>>>>> perform: Synchronize unmigrated apps: allauth, crispy_forms Apply 
>>>>>> all migrations: account, sessions, admin, sites, profiles, 
>>>>>> contenttypes, authSynchronizing apps w

Re: [django 1.7.6] system error: 10054 An existing connection was forcibly closed by the remote host

2015-03-12 Thread Collin Anderson
Hi,

Interesting. If you switch back to previous version of django you don't 
have that problem?

Is it a slow query?

Are you using MySQL or MSSQL?

Collin

On Tuesday, March 10, 2015 at 8:55:44 PM UTC-4, Weifeng Pan wrote:
>
> Hi,
>
>
> I upgrade to latest version of django.  Every time I navigate to django 
> admin site "User" page.  I got this error:
>
> File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\core\handlers\base.py", 
> line 111, in get_response
> response = wrapped_callback(request, *callback_args, **callback_kwargs)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\contrib\admin\options.py",
>  
> line 583, in wrapper
> return self.admin_site.admin_view(view)(*args, **kwargs)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\utils\decorators.py", 
> line 105, in _wrapped_view
> response = view_func(request, *args, **kwargs)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\views\decorators\cache.py",
>  
> line 52, in _wrapped_view_func
> response = view_func(request, *args, **kwargs)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\contrib\admin\sites.py", 
> line 206, in inner
> return view(request, *args, **kwargs)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\utils\decorators.py", 
> line 29, in _wrapper
> return bound_func(*args, **kwargs)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\utils\decorators.py", 
> line 105, in _wrapped_view
> response = view_func(request, *args, **kwargs)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\utils\decorators.py", 
> line 25, in bound_func
> return func.__get__(self, type(self))(*args2, **kwargs2)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\contrib\admin\options.py",
>  
> line 1485, in changelist_view
> self.list_max_show_all, self.list_editable, self)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\contrib\admin\views\main.py",
>  
> line 109, in __init__
> self.queryset = self.get_queryset(request)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\contrib\admin\views\main.py",
>  
> line 359, in get_queryset
> filters_use_distinct) = self.get_filters(request)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\contrib\admin\views\main.py",
>  
> line 175, in get_filters
> self.model, self.model_admin, field_path=field_path)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\contrib\admin\filters.py",
>  
> line 158, in create
> model, model_admin, field_path=field_path)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\contrib\admin\filters.py",
>  
> line 172, in __init__
> self.lookup_choices = field.get_choices(include_blank=False)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\db\models\fields\__init__.py",
>  
> line 750, in get_choices
> self.get_limit_choices_to())]
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\db\models\query.py", 
> line 141, in __iter__
> self._fetch_all()
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\db\models\query.py", 
> line 966, in _fetch_all
> self._result_cache = list(self.iterator())
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\db\models\query.py", 
> line 265, in iterator
> for row in compiler.results_iter():
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\db\models\sql\compiler.py",
>  
> line 700, in results_iter
> for rows in self.execute_sql(MULTI):
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\db\models\sql\compiler.py",
>  
> line 786, in execute_sql
> cursor.execute(sql, params)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\db\backends\utils.py", 
> line 81, in execute
> return super(CursorDebugWrapper, self).execute(sql, params)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\django\db\backends\utils.py", 
> line 65, in execute
> return self.cursor.execute(sql, params)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\mysql\connector\django\base.py", 
> line 135, in execute
> return self._execute_wrapper(self.cursor.execute, query, args)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\mysql\connector\django\base.py", 
> line 124, in _execute_wrapper
> utils.DatabaseError(err.msg), sys.exc_info()[2])
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\mysql\connector\django\base.py", 
> line 115, in _execute_wrapper
> return method(query, args)
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\mysql\connector\cursor.py", 
> line 507, in execute
> self._handle_result(self._connection.cmd_query(stmt))
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-packages\mysql\connector\connection.py", 
> line 722, in cmd_query
> result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
>   File 
> "C:\MyProjects\WuWuKe\venv\lib\site-pack

Re: Filtering a QuerySet by the result of user.has_perm

2015-03-12 Thread Collin Anderson
Hi Adam,

It's pretty inefficient, but you can do:
MyModel.objects.filter(pk__in=[obj.pk for obj in MyModel.objects.all() if 
user.has_perm('read', obj)])

But, actually, I think you want to use get_objects_for_user():
http://django-guardian.readthedocs.org/en/v1.2/userguide/check.html#get-objects-for-user

Collin

On Tuesday, March 10, 2015 at 5:47:57 PM UTC-4, Adam Gamble wrote:
>
> Hi all,
>
> I'm stuck on how to restructure the following in order to return a 
> QuerySet instead of a List (needed for Lazy evaluation):
>
> filter(lambda o: user.has_perm('read', o), MyModel.objects.all())
>
> Using django-guardian , for 
> object-level permissions.
>
> Appreciate any ideas,
>
> Adam
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d4e2e9f4-941d-4cf9-b77e-b7a2bacb54fb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Getting 500 error on ASO

2015-03-11 Thread Collin Anderson
Hi Michael,

Are you checking your Apache log? Also, be sure to set up ADMINS so you can 
get emails for any django errors.

I believe runfastcgi is gone from django now, along with all 
of django.core.servers.fastcgi.

At work we used to host on ASO too. We now use Linode. Digital Ocean is 
good too.

Collin

On Monday, March 9, 2015 at 9:57:47 PM UTC-4, mfox_chi wrote:
>
> Hi Everyone,
>
> I've been working on learning Django the past few months and have been 
> following the django tutorials here:
>
> https://docs.djangoproject.com/en/1.7/.
>
> I've followed the tutorial on my local machine in addition to on my A 
> Small Orange account.
>
> A Small Orange has this tutorial:
>
>
> https://kb.asmallorange.com/customer/portal/articles/1603414-install-django-using-virtualenv
>
> which has gotten me to reach the default django "Congrats" webpage. This 
> pages appears on both my local machines django setup and the ASO website. 
> The next step is to run the startapp function within the mysite folder.
>
> My folder structure is as follows on the ASO server
>
> home/"username"/
>website/
>   mysite/ 
> polls/ (after I run the startapp command)
>(all the startapp default files) 
> mysite/
>  (all the startproject default files)
>   public_html/
>   dispatch.fcgi
>   .htaccess
>
> My issue is that when I run "python27 manage.py startapp polls" from 
> within the website/mysite folder my server immediately goes to a 500 
> internal server error page online while this function causes no issues on 
> my local computer.
>
> The only lead I have on the problem currently is that when I run my 
> dispatch.fcgi file via "python27 dispatch.fcgi" from within the public_html 
> directory I get the HTML output that should be up on my website. The output 
> is shown within my SSH. This makes me think the error has something to do 
> with the communication between the .htaccess file and the dispatch file. 
>
> -dispatch.fcgi 
>
> from traceback import formate_exc
> try:
> #!/home#/theopeni/.env/env/bin/python
>
>  import sys
>  import os
>
>  sys.path.insert(0, 
> "/home/(myusername)/.env/env/lib/python2.7/site-packages")
>  sys.path.append("/home/(my username)/website/mysite/mysite")
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> from django.core.servers.fastcgi import runfastcgi
> runfastcgi(method="threaded", daemonize="false")
>
> except Exception:
> open("/home/(my username)/website/error.txt", "w").write(format_exc())
> raise
>
> -.htaccess
>
> AddHandler fcgi-script .fcgi
> RewriteEngine On
> RewriteCon %{REQUEST_FILENAME} !-f
> RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]
>
> I've talked to the ASO customer support and I worked with a technical 
> support person for about a week to solve it and they were able to get an 
> app started without error but then told me that this was beyond the scope 
> of their customer support. I then tried adding my own app with the python27 
> manage.py startapp command and it broke the website again. 
>
> Has anyone else encountered this problem?
>
> Thank you!
>
> Michael
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8bd55f77-8617-43bf-9d88-4d04e95683d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django server serving cached template pages

2015-03-10 Thread Collin Anderson
Hi,

Yes, apparently many people get tripped up on this step. Is this django1.7?

create a blank "blank_site.html".  <- I assume you mean create a blank 
base_site.html?

I assume this is with manage.py runserver? (If it's apache/uwsgi/gunicorn, 
you need to reload the program when changing the setting.)

Caching should only be an issue if the cached template loader is installed, 
which it isn't by default.

Collin

On Sunday, March 8, 2015 at 4:10:09 PM UTC-4, Bryan Arguello wrote:
>
> I am on the second page of the blog tutorial and am trying to change the 
> base-site.html template.  
>
> I make a few small changes, set the permissions to 755, put it in
> a subdirectory named 'admin' within a directory called 'template' inside 
> of the project directory.  
>
> I also add the template directory path to the TEMPLATE_DIRS variable
> in settings.py and restart the server.  
>
> After several hours of trying things suggested in different forums on this 
> topic, I decided to just rename the original base_site.html in 
> django/contrib/admin/templates/admin and create a blank "blank_site.html".  
>
> After doing this, one would expect to get a blank page if the templates in 
> TEMPLATE_DIRS were not found.  However, I am getting the same "Django 
> administration" page.  Also, I did go into the manage.py shell and check 
> TEMPLATE_DIRS: it is set to the correct directory.  I am starting to think 
> this is some kind of Django server cache issue (tried clearing browser 
> cache).
>
> I can see that many new-comers to Django have come across this issue and 
> none of the suggestions for these users seem to work.  However, I have 
> never seen anyone mention a cache being the issue.  Does anyone have any 
> suggestions?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1e222d27-64fc-44e3-909a-2668a7f3d1e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: my mysite/templates/admin/base_site.html is ignored (tutorial unclear?)

2015-03-10 Thread Collin Anderson
Hi,

To be clear, you should have this setting:
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

and in your mysite/templates/admin/base_site.html you should have something 
like:

{% block branding %}
Polls 
Administration
{% endblock %}

Does that all look right?

Thanks,
Collin

On Sunday, March 8, 2015 at 3:09:19 PM UTC-4, Bryan Arguello wrote:
>
> Have you solved this problem, Andreas?  I am having the same issue and 
> have done
> everything that the tutorial described as well as everything that people 
> on this thread
> have suggested.
>
> On Sunday, November 16, 2014 at 12:15:59 PM UTC-6, Andreas Ka wrote:
>>
>> I am working through 
>> https://docs.djangoproject.com/en/1.7/intro/tutorial02 
>> 
>> so far all went fine - but now *templates changes just don't work.*
>>
>>
>>
>> I think there must be a flaw in that tutorial, something missing,
>> or something different in django 1.7.1 ?
>>
>> https://docs.djangoproject.com/en/1.7/intro/tutorial02/#customize-the-admin-look-and-feel
>>
>>
>> my versions:
>>
>> python -c "import django; print(django.get_version())"
>> 1.7.1
>>
>> python --version
>> Python 2.7.3
>>
>>
>>
>> *SYMPTOM:*
>>
>> my changes in 
>> mysite/templates/admin/base_site.html   
>> are simply ignored.
>>
>>
>>
>> These are my files:
>>
>> mysite# tree
>> .
>> ├── db.sqlite3
>> ├── manage.py
>> ├── mysite
>> │   ├── __init__.py
>> │   ├── settings.py
>> │   ├── urls.py
>> │   └── wsgi.py
>> ├── polls
>> │   ├── admin.py
>> │   ├── __init__.py
>> │   ├── migrations
>> │   │   ├── 0001_initial.py
>> │   │   └── __init__.py
>> │   ├── models.py
>> │   ├── tests.py
>> │   └── views.py
>> └── templates
>> └── admin
>> └── base_site.html
>>
>>
>>
>> mysite/settings.py:
>>
>> TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
>>
>>
>> *Whatever I do, the page*
>> *http://myserver:8000/admin/polls/question/ 
>> *
>> *still keeps the old title 'Django administration'*
>>
>>
>> I want to understand how templates work, because I need them for my real 
>> project.
>>
>> Thanks a lot!
>>
>>
>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/74b79ef9-b70a-4a1c-956e-9364378c12bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing Django models using DJANGO_SETTINGS_MODULE

2015-03-10 Thread Collin Anderson
Hi,

Hmm... maybe try ChatRoom.objects.all().all() ? :)

If you run this, you can see if it's actually running sql or not:
import logging; logging.basicConfig(level=logging.DEBUG)

Are you sure you're using the same database? :)

Collin

On Sunday, March 8, 2015 at 8:41:30 AM UTC-4, Dheerendra Rathor wrote:
>
> I've a django project and I've few models like ChatRoom and Chat etc
>
> I'm accessing the ChatRooms from commandline using ipython as follow
> In [1]: import os
>
> In [2]: os.environ['DJANGO_SETTINGS_MODULE'] = 'chat_project.settings'
>
> In [3]: from chat.models import Chat, ChatRoom
>
> In [4]: ChatRoom.objects.all()
> Out[4]: [, , , 
> , , ,  07>, , , ,  Lab 15>, ]
>
> Now, I'm adding more ChatRooms through web interface - Lab 17, Lab 18 and 
> deleting Lab 10
> Now the new output of 
> In [5]: ChatRoom.objects.all()
>
> The output is still the same
> Out[5]: [, , , 
> , , ,  07>, , , ,  Lab 15>, ]
>
> the webinterface is running as wsgi application on gunicorn server. 
>
> I think the output on command line is not changed because the django 
> default model manager is accessing the objects from cache and not from 
> database itself. Is there anyway I can get the updated models here on 
> command line? Or can I force django ORM to fetch objects from database and 
> not from cache?
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/737ec68b-d2eb-46be-a86a-8703f665e4bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Existing database - new project

2015-03-10 Thread Collin Anderson
Hi,

inspectdb makes step #1 much easier.

If you're not planning on removing some of the columns or restructuring 
things, I'd recommend #1.

Collin 

On Saturday, March 7, 2015 at 9:31:24 AM UTC-5, Derek wrote:
>
> I have taken route 1 before; its a bit more messy because you may have to 
> explicitly map your desired model names to the actual column names.  You 
> also face the issue of dealing with primary keys. 
>
> If you have the choice, and the current database is not in use anymore, I 
> would create a new one, using Django conventions (such as an auto-increment 
> primary key, with "unique_together" constraints) and then import the 
> existing data.  This has the added benefit of allowing you to validate the 
> existing data and ensure that you start with a 'clean' data set. 
>
> HTH
> Derek
>
> On Friday, 6 March 2015 23:39:33 UTC+2, Robert Daniels wrote:
>>
>> I understand it is possible to use an existing database on a new Django 
>> project. 
>>
>> As I see it, I have 2 choices.
>>
>> 1 - Use the existing database and deal with it in that fashion.
>>
>> or
>>
>> 2 - Create a new project to store the same type of data as if there were 
>> no existing database, Then write a separate export-import script to move 
>> the data from the existing db to the new structure. 
>>
>> Wondering if anyone has gone through the "good" and "bad" of each of 
>> these. I have about 100,000 records in the database, but moving the data 
>> across should not be that difficult as its a pretty flat model
>>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/374949d8-09a9-4dcc-bdde-76dcd1d9f795%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django OperationalError

2015-03-10 Thread Collin Anderson
Hi Petar,

I'm actually not sure why you want to call sqlflush. If you're trying to 
clear out the database, you may need to delete the migrations table 
manually, but it just might be simpler to delete the either database and 
re-create it, rather than the individual tables.

Collin

On Friday, March 6, 2015 at 11:24:19 PM UTC-5, Petar Pilipovic wrote:
>
> Hello Collin,
> No the problem is, i have tried to drop mine migrations whit python manage 
> sqlflush, then I have recreate the db whit 
> python manage.py migrate.
> Here this is the all operation whit python manage sqlflush, syncdb, 
> migrate <http://ur1.ca/jv371>. I have notice that there was no migration 
> to apply at the end, and the error is still there.
> Is there something else I can do, or how can I approach this differently.
> Best
> Petar
>
> On Fri, Mar 6, 2015 at 11:21 PM, Collin Anderson  > wrote:
>
>> Hi,
>>
>> The problem is that django_session doesn't exist in your database. Either 
>> it was never created or it was created and then later deleted.
>>
>> Does running manage.py migrate re-create it?
>>
>> Collin
>>
>> On Monday, March 2, 2015 at 11:36:51 PM UTC-5, Petar Pilipovic wrote:
>>>
>>> Hello James, sorry for not uploading mine answer on this mater, I was 
>>> busy whit something else this day, ok now back to mine Operational Error I 
>>> have got.
>>> I tried to google some solution to this problem had no luck, and I did 
>>> what have you told me.
>>> I heave done some 
>>> python manage.py sqlflush
>>>
>>> and that has gave me this output: 
>>>
>>> (django17)04:20 ~/mineDjango$ python manage.py sqlflush BEGIN;DELETE 
>>> FROM "django_admin_log";DELETE FROM "auth_permission";DELETE FROM 
>>> "auth_group";DELETE FROM "auth_group_permissions";DELETE FROM 
>>> "django_session";DELETE FROM "auth_user_groups";DELETE FROM 
>>> "auth_user_user_permissions";DELETE FROM "account_emailaddress";DELETE 
>>> FROM "django_site";DELETE FROM "profiles_profile";DELETE FROM 
>>> "auth_user";DELETE FROM "profiles_userstripe";DELETE FROM 
>>> "account_emailconfirmation";DELETE FROM "django_content_type";COMMIT;
>>>
>>> Then I have done 
>>> python manage.py syncdb python manage.py migrate
>>>
>>> Output of mine recreating tables are this:
>>> (django17)04:20 ~/mineDjango$ python manage.py syncdbOperations to 
>>> perform: Synchronize unmigrated apps: allauth, crispy_forms Apply all 
>>> migrations: account, sessions, admin, sites, profiles, contenttypes, 
>>> authSynchronizing apps without migrations: Creating tables... 
>>> Installing custom SQL... Installing indexes...Running migrations: No 
>>> migrations to apply.(django17)04:20 ~/mineDjango$ python manage.py 
>>> migrateOperations to perform: Synchronize unmigrated apps: allauth, 
>>> crispy_forms Apply all migrations: account, sessions, admin, sites, 
>>> profiles, contenttypes, authSynchronizing apps without migrations: 
>>> Creating tables... Installing custom SQL... Installing indexes...Running 
>>> migrations: No migrations to apply.
>>> Basically I have had no changes in mine attempt to drop and recreate 
>>> tables in mine application.
>>> The error is still there.
>>> Error:
>>> Environment:
>>>
>>>
>>>
>>>
>>> Request Method: GET
>>> Request URL: http://copser.pythonanywhere.com/
>>>
>>>
>>> Django Version: 1.7.2
>>> Python Version: 2.7.6
>>> Installed Applications:
>>> ('django.contrib.admin',
>>>  'django.contrib.auth',
>>>  'django.contrib.contenttypes',
>>>  'django.contrib.sessions',
>>>  'django.contrib.messages',
>>>  'django.contrib.staticfiles',
>>>  'profiles',
>>>  'crispy_forms',
>>>  'django.contrib.sites',
>>>  'allauth',
>>>  'allauth.account',
>>>  'stripe')
>>> Installed Middleware:
>>> ('django.contrib.sessions.middleware.SessionMiddleware',
>>>  'django.middleware.common.CommonMiddleware',
>>>  'django.middleware.csrf.CsrfViewMiddleware',
>>>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>>>  'django.

Re: Django Admin Page

2015-03-06 Thread Collin Anderson
Hi,

That's odd. Maybe try updating django? It looks like you're using 1.8 
pre-alpha from 3 months ago.

Collin

On Friday, February 20, 2015 at 1:40:03 AM UTC-5, Tim Co wrote:
>
> Hello,
>
> We are trying to run a local development server for our django python app. 
> We are able to connect to our localhost index and get the "It Worked!" 
> Dango page. However when we try to connect to 127.0.0.1/admin/ we are 
> getting an error that the server dropped the connection. Here is the log 
> for the django project:
>
> Exception happened during processing of request from ('130.191.204.231', 
> 62070)
> Traceback (most recent call last):
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/
> lib/python2.7/SocketServer.py", line 593, in process_request_thread
> self.finish_request(request, client_address)
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/
> lib/python2.7/SocketServer.py", line 334, in finish_request
> self.RequestHandlerClass(request, client_address, self)
>   File "/Library/Python/2.7/site-packages/Django-1.8.
> dev20141212211410-py2.7.egg/django/core/servers/basehttp.py", line 101, 
> in __init__
> super(WSGIRequestHandler, self).__init__(*args, **kwargs)
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/
> lib/python2.7/SocketServer.py", line 649, in __init__
> self.handle()
>   File "/Library/Python/2.7/site-packages/Django-1.8.
> dev20141212211410-py2.7.egg/django/core/servers/basehttp.py", line 173, 
> in handle
> handler.run(self.server.get_app())
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/
> lib/python2.7/wsgiref/handlers.py", line 92, in run
> self.close()
>   File "/System/Library/Frameworks/Python.framework/Versions/2.7/
> lib/python2.7/wsgiref/simple_server.py", line 33, in close
> self.status.split(' ',1)[0], self.bytes_sent
> AttributeError: 'NoneType' object has no attribute 'split'
>
> 
> ///
> Our urls.py file
>
> urls.py
>
> from django.conf.urls import include, url
> from django.contrib import admin
>
> admin.autodiscover()
>
> urlpatterns = [
> # Examples:
> # url(r'^$', 'mysite.views.home', name='home'),
> # url(r'^blog/', include('blog.urls')),
> url(r'^admin/', include(admin.site.urls)),
> ]
>
>
> 
> ///
> settings.py
>
>
> # Application definition
>
> INSTALLED_APPS = (
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'trainstar',
> )
>
> MIDDLEWARE_CLASSES = (
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> 'django.middleware.security.SecurityMiddleware',
> )
>
> TEMPLATE_CONTEXT_PROCESSORS = (
> "django.contrib.auth.context_processors.auth",
> "django.core.context_processors.debug",
> "django.core.context_processors.i18n",
> "django.core.context_processors.media",
> "django.core.context_processors.static",
> "django.core.context_processors.tz",
> 'django.contrib.messages.context_processors.messages'
> )
>
>
> ROOT_URLCONF = 'mysite.urls'
>
> WSGI_APPLICATION = 'mysite.wsgi.application'
>
>
> Please advise. I've exhausted Google/stackoverflow for possible fixes to 
> of no avail. 
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e15cb4e6-bf0a-453b-8262-d0a9a5b9312f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how pass get parameter django bootstrap pagination

2015-03-06 Thread Collin Anderson
Hi,

If you have the request context processor installed, you can do this:

{% bootstrap_paginate object_list range=request.GET.range %}

Collin

On Thursday, March 5, 2015 at 4:35:33 AM UTC-5, SHINTO PETER wrote:
>
>  {% load bootstrap_pagination %}
>   {% bootstrap_paginate object_list range=10 %}
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c135d389-2bac-46b1-8816-287f35fa20cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: getting tuples from http request.GET

2015-03-06 Thread Collin Anderson
Hi,

Normally query arguments are separated by &. If you're able to send the 
data like this:

https://mydesktop.com/validator?hostname1=host1.example.com&location1=ca&ip1=2.2.2.2&hostname2=host2.example.com&location2=wa&ip2=3.3.3.3

Then you could do something like:

data = []
i = 0
while True:
i += 1
try:
data.append((request.GET['hostname%s' % i], request.GET['location%s' 
% i], request.GET['ip%s' % i]))
except KeyError:
break

Collin

On Wednesday, March 4, 2015 at 7:57:17 PM UTC-5, Sunil Sawant wrote:

> Hi Guys,
>
> Pretty new to Django, but used it blindly and works wonders. But here is a 
> situation I am blocked at now for a new project
>
> I request.GET the following URL
>
>
> https://mydesktop.com/validator?hostname1=host1.example.com,location1=ca,ip1=2.2.2.2,hostname2=host2.example.com,location2=wa,ip2=3.3.3.3
>
> Am using request.GET I want to get the output in a tuple or hash form as:
>
> [{host1.example.com:[ca,2.2.2.2]},{host2.example.com:[wa,3.3.3.3]}]
>
>
>
> Once I have this data I can process it further.
> Please help
>
>
>
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/438392a2-4d17-4e91-bfe9-27ae17e2a80a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Rolling back to practice on old bugs

2015-03-06 Thread Collin Anderson
Hi,

I always type: PYTHONPATH=.. ./runtests.py

Collin

On Wednesday, March 4, 2015 at 4:30:54 PM UTC-5, Javis Sullivan wrote:
>
> I am following this tutorial here 
>  "Writing your 
> first Django patch" and while it directs me to rollback to this 
> 39f5bc7fc3a4bb43ed8a1358b17fe0521a1a63ac 
> 
>  commit, 
> when I do so I am not able to run the runtests.py script. I guess the 
> directory structure or something has changed along the way, I assume. As I 
> am getting the error below:
>
> Traceback (most recent call last):
>   File "runtests.py", line 327, in 
> options.failfast, args)
>   File "runtests.py", line 153, django_tests
> state = setup(verbosity, test_labels)
>   File "runtests.py", line 111, in setup
> from django.db.models.loading import get_apps, load_app
> ImportError: No module named 'django.db.models.loading'
>
>
>
> I poked around to see if I could find the loadings module but it is not 
> longer there. Should I just practice on a recent bug? Because runtests.py 
> does fine when the git head is located at the most recent commit. 
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1c17d272-ab2f-4f46-941d-d936a826ff33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Populating Django app db with JSON data

2015-03-06 Thread Collin Anderson
Hi Sandeep,

A snapshot (or at least a diff from the previous one) is stored when you 
run makemigrations.

Collin

On Wednesday, March 4, 2015 at 2:15:41 PM UTC-5, Murthy Sandeep wrote:
>
> Hi 
>
> thanks for the info. 
>
> The docs also say that RunPython runs “custom Python code 
> in a historical context”.  What does that mean exactly?  It seems 
> related to the apps and schema_editor arguments passed to 
> the custom method that will be called by RunPython - is this something 
> like a snapshot of the app model that is stored when I do `python 
> manage.py migrate`? 
>
> Sandeep 
>
>
> > On 2 Mar 2015, at 19:37, aRkadeFR > 
> wrote: 
> > 
> > Hello, 
> > 
> > Indeed, the data migration is the best way. Check out 
> > the documentation here: 
> > 
> https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunPython
>  
> > 
> > You write your function that will be called by the RunPython 
> > and will load your JSON. 
> > Migration are ordered, your first migration will create the 
> > tables and the second (your data migration) will load your 
> > JSON. 
> > 
> > To create an empty migration: 
> > ./manage.py makemigrations  --empty 
> > 
> > You can rename to a useful descriptive name the migration 
> > file. 
> > 
> > Have a good one 
> > 
> > 
> > On 03/02/2015 08:16 AM, Sandeep Murthy wrote: 
> >> Hi 
> >> 
> >> I've tried to get the answer to this question (which is a bit 
> open-ended) on stackoverflow without much success, which 
> >> is basically this: what is the recommended approach to populating a 
> pre-existing Django app database table (generated 
> >> from a model and which is currently empty) with JSON data? 
> >> 
> >> There seem to be several alternatives given in the Django documentation 
> (Django 1.7 manual) which include (1) fixtures, 
> >> (2) SQL scripts, (3) data migrations.  Of these I am a bit confused by 
> the advice in the manual which suggests that (1) 
> >> and (2) are only useful for loading initial data.  That's not what I 
> want to do.  The data that the app needs is going to be 
> >> persistent and permanent because the app is intended to be a web query 
> tool for a large dataset that is currently in the 
> >> form of several JSON files, each containing on average thousands of 
> JSON objects, each object representing an entry 
> >> corresponding to a table entry in a relational db.  The data is not 
> going to be re-loaded or change after entry, and there 
> >> is no user facility for changing the data. 
> >> 
> >> The table has been created using the makemigrations and migrate tools, 
> but is empty.  I just need to populate the 
> >> table with the JSON data.  It seems that I need to write a custom data 
> migration script that will insert the data into the 
> >> table via the interpreter, and then I need to run python manage.py 
> migrate.  Is this the case, and if so, are there 
> >> are examples that I could use? 
> >> 
> >> Thanks in advance for any suggestions. 
> >> 
> >> SM 
> >> -- 
> >> 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 http://groups.google.com/group/django-users. 
> >> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/db5919c5-ace4-4556-b90e-aa47baa26552%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...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at http://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/54F42164.6040505%40arkade.info.
>  
>
> > 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d78e387b-9232-4a5a-b6d5-1306b5084913%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django(1.7) admin - separate user-profile section

2015-03-06 Thread Collin Anderson
Hi,

If you just add a custom __str__ (or __unicode__ on py2) it might do what 
you want.

def __str__(self):
return str(user)

Otherwise, in UserTokenAdmin, set list_display = ['user']

Collin

On Wednesday, March 4, 2015 at 2:15:32 PM UTC-5, Flemming Hansen wrote:
>
> Hi all,
>
> I need to make a `passwordless` token system, and want to have a "Home › 
> Passwordless › User tokens" in the Admin section. For the "User tokens" 
> `list_display` I need all the "Users". (I do _not_ want to display the 
> token information on the regular "User"-admin as just an extended 
> "profile".) 
>
> Any ideas on how to go about doing this?
>
> So far I have this skeleton in `passwordless/model.py`, but I probably 
> need some magic in `passwordless/admin.py` to list all the users with links 
> to a custom token-manager form with custom widgets (create-token button, 
> delete token button etc)...
>
> from django.db import models
> import jwt
>
> class UserTokens(models.Model):
> class Meta:
> verbose_name = "User tokens"
> verbose_name_plural = "User tokens"
>
> user = models.OneToOneField(User)
>
>
> class TokenBase(models.Model):
> class Meta:
> abstract = True
>
> token = models.CharField(max_length=1000)
> created_ts = models.DateTimeField('Date created')
> expires_ts = models.DateTimeField('Date expired')
>
> def __str__(self):
> return self.user.email
>
>
> class AuthenticateToken(TokenBase):
> manager = models.OneToOneField(UserTokens)
>
> def validate(self, token):
> pass
>
>
> class AuthorizeToken(TokenBase):   
> manager = models.ForeignKey(UserTokens)
> revoked_ts = models.DateTimeField('Date revoked')
>
> def validate(self, token):
> pass  
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/783e5939-eb30-4f5d-ab9c-29002a5523b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.7 tutorial part 4, url

2015-03-06 Thread Collin Anderson
Hi,

That seems strange. The error says that there's no question with id=1. Are 
you sure there's a question with id=1?

The ending slash seems important to me. I don't know why it would work 
without it.

Collin

On Wednesday, March 4, 2015 at 2:15:32 PM UTC-5, Daniel Altschuler wrote:
>
> I ran into the following problem with the tutorial.
>
> When I'm at http://127.0.0.1:8000/polls/1/, I get the expected page:
>
> What's up? Not much
>  The sky
>
>
> However when I try to vote I get the error 
>
> Page not found (404)Request Method:POSTRequest URL:
> http://127.0.0.1:8000/polls/1/vote/
>
> No Question matches the given query.
>
> You're seeing this error because you have DEBUG = True in your Django 
> settings file. Change that to False, and Django will display a standard 
> 404 page.
>
> After some time I found that something is wrong with the urls. My 
> polls/urls.py file was:
>
> -
> from django.conf.urls import patterns, url
>
> from polls import views
>
> urlpatterns = patterns('',
> # ex: /polls/
> url(r'^$', views.index, name='index'),
> # ex: /polls/5/
> url(r'^(?P\d+)/$', views.detail, name='detail'),
>
> url(r'^(?P\S+)/$', views.search, name='search'),
> # ex: /polls/5/results/
> url(r'^(?P\d+)/results/$', views.results, name='results'),
> # ex: /polls/5/vote/
> url(r'^(?P\d+)/vote/$', views.vote, name='vote'),
> )
> --
>
> If I remove the "/" after "vote", then everything works. I had the same 
> error when attempting to view the results, so I also
> removed the "/" after results. My urls.py now looks like
>
> ...
> # ex: /polls/5/results
> url(r'^(?P\d+)/results$', views.results, name='results'),
> # ex: /polls/5/vote
> url(r'^(?P\d+)/vote$', views.vote, name='vote'),
>...
>
> Can someone explain me what is going on? thanks.
>
> Note that the file mysite/urls.py is:
>
> --
> from django.conf.urls import patterns, url
>
> from polls import views
>
> urlpatterns = patterns('',
> # ex: /polls/
> url(r'^$', views.index, name='index'),
> # ex: /polls/5/
> url(r'^(?P\d+)/$', views.detail, name='detail'),
>
> url(r'^(?P\S+)/$', views.search, name='search'),
> # ex: /polls/5/results
> url(r'^(?P\d+)/results$', views.results, name='results'),
> # ex: /polls/5/vote
> url(r'^(?P\d+)/vote$', views.vote, name='vote'),
> )
> 
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/db705c9f-f8a1-46e6-add8-a637671a603e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fatal Error in initializing sys standard streams

2015-03-06 Thread Collin Anderson
Hi,

That doesn't look good :)

Maybe try reinstalling python.

Collin

On Wednesday, March 4, 2015 at 11:11:12 AM UTC-5, sriraag paawan wrote:
>
>
> Hello Guys,
>
> I am new to Django.. i am using Django 1.7.4 and Python 3.4
>
> I was about to complete Django tutorial part-5 about tests but a Fatal 
> Error caused me trouble.. I am attaching an image file which contains 
> detail view of my problem... Please anyone could figure it out and solve 
> it..
>
> Thank You in Advance
>
>
> 
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eab4c651-8b4c-4840-a5b6-55593f8cd5bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can't make ManyToMany form fields hidden

2015-03-06 Thread Collin Anderson
https://code.djangoproject.com/ticket/24453

On Wednesday, March 4, 2015 at 12:40:40 AM UTC-5, Eric Abrahamsen wrote:
>
> Hi, 
>
> I'm making some heavily customized model formsets, to encourage my users 
> to input data. Mostly that involves cutting down the number of huge 
> drop-down menus they have to go surfing through. 
>
> So I have a model like this: 
>
> class Work(models.Model): 
>   authors = models.ManyToManyField(Author,blank=True,related_name="works") 
>
> I first present them with a pre-query form, to choose an Author, then 
> give them a Work modelformset with the "authors" field pre-filled with 
> that author. So the initial data sort of looks like: 
>
> init["authors"] = [pre_query.cleaned_data["authors"]] # must be a list 
>
> for i in range(0, number_of_additional_forms): 
>   initial.append(init) 
>
> formset = WorkFormSet(queryset=Work.objects.none(), initial=initial) 
>
> Nothing unusual there. Now I want to make the "authors" field hidden. 
> This is both to reassure my users, and to reduce the size of the page -- 
> these are really long dropdowns. 
>
> Adding the hidden widget to the "authors" field, however, gives me this 
> validation error: 
>
> (Hidden field authors) Enter a list of values. 
>
> The form input field looks like this: 
>
>  value="[37L]" /> 
>
> Looks like a list of values to me, but maybe it's not getting read that 
> way. 
>
> In the meantime it's not a disaster if the monster "authors" dropdown is 
> visible for each of my Work forms, but it would be really nice to 
> eventually get it hidden. 
>
> In the past I did this by manually *removing* fields from the forms, and 
> adding the values in during the POST/save process, but that always felt 
> bad to me. 
>
> Thanks! 
> Eric 
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53c18174-9439-462d-8a8e-34783a065bcf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django OperationalError

2015-03-06 Thread Collin Anderson
Hi,

The problem is that django_session doesn't exist in your database. Either 
it was never created or it was created and then later deleted.

Does running manage.py migrate re-create it?

Collin

On Monday, March 2, 2015 at 11:36:51 PM UTC-5, Petar Pilipovic wrote:
>
> Hello James, sorry for not uploading mine answer on this mater, I was busy 
> whit something else this day, ok now back to mine Operational Error I have 
> got.
> I tried to google some solution to this problem had no luck, and I did 
> what have you told me.
> I heave done some 
> python manage.py sqlflush
>
> and that has gave me this output: 
>
> (django17)04:20 ~/mineDjango$ python manage.py sqlflush BEGIN;DELETE FROM 
> "django_admin_log";DELETE FROM "auth_permission";DELETE FROM "auth_group";
> DELETE FROM "auth_group_permissions";DELETE FROM "django_session";DELETE 
> FROM "auth_user_groups";DELETE FROM "auth_user_user_permissions";DELETE 
> FROM "account_emailaddress";DELETE FROM "django_site";DELETE FROM 
> "profiles_profile";DELETE FROM "auth_user";DELETE FROM 
> "profiles_userstripe";DELETE FROM "account_emailconfirmation";DELETE FROM 
> "django_content_type";COMMIT;
>
> Then I have done 
> python manage.py syncdb python manage.py migrate
>
> Output of mine recreating tables are this:
> (django17)04:20 ~/mineDjango$ python manage.py syncdbOperations to 
> perform: Synchronize unmigrated apps: allauth, crispy_forms Apply all 
> migrations: account, sessions, admin, sites, profiles, contenttypes, 
> authSynchronizing 
> apps without migrations: Creating tables... Installing custom SQL... 
> Installing indexes...Running migrations: No migrations to 
> apply.(django17)04:20 
> ~/mineDjango$ python manage.py migrateOperations to perform: Synchronize 
> unmigrated apps: allauth, crispy_forms Apply all migrations: account, 
> sessions, admin, sites, profiles, contenttypes, authSynchronizing apps 
> without migrations: Creating tables... Installing custom SQL... 
> Installing indexes...Running migrations: No migrations to apply.
> Basically I have had no changes in mine attempt to drop and recreate 
> tables in mine application.
> The error is still there.
> Error:
> Environment:
>
>
>
>
> Request Method: GET
> Request URL: http://copser.pythonanywhere.com/
>
>
> Django Version: 1.7.2
> Python Version: 2.7.6
> Installed Applications:
> ('django.contrib.admin',
>  'django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.messages',
>  'django.contrib.staticfiles',
>  'profiles',
>  'crispy_forms',
>  'django.contrib.sites',
>  'allauth',
>  'allauth.account',
>  'stripe')
> Installed Middleware:
> ('django.contrib.sessions.middleware.SessionMiddleware',
>  'django.middleware.common.CommonMiddleware',
>  'django.middleware.csrf.CsrfViewMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
>  'django.contrib.messages.middleware.MessageMiddleware',
>  'django.middleware.clickjacking.XFrameOptionsMiddleware')
>
>
>
>
> Template error:
> In template /home/copser/static/templates/home.html, error at line 40
>no such table: django_session
>30 :  
>
>
>
>
>31 : {% block content %}
>
>
>
>
>32 :  
>
>
>
>
>33 : 
>
>
>
>
>34 :   
>
>
>
>
>35 : 
>
>
>
>
>36 : 
>
>
>
>
>37 :  {#   src="{% static 'img/07.jpg' %}"/>  #}
>
>
>
>
>38 :
>
>
>
>
>39 : 
>
>
>
>
>40 :  {% if request.user.is_authenticated %} 
>
>
>
>
>41 : Hello {{ request.user }}
>
>
>
>
>42 : {% else %}
>
>
>
>
>43 :   
>
>
>
>
>44 :  value="sczg1f8U4tWQRa8kgNJC1QsSBKAD9Lvw"> {% csrf_token %}
>
>
>
>
>45 :  for="id_login" class="control-label  requiredField">
>
>
>
>
>46 : Login class="asteriskField">* autofocus="autofocus" class="textinput textInput form-control" 
> id="id_login" name="login" placeholder="Username or e-mail" type="text"> 
>  for="id_password" class="control-label  requiredField">
>
>
>
>
>47 : Password class="asteriskField">* class="textinput textInput form-control" id="id_password" name="password" 
> placeholder="Password" type="password">  class="form-group"> for="id_remember" class=""> id="id_remember" name="remember" type="checkbox">
>
>
>
>
>48 : Remember Me
>
>
>
>
>49 : 
>
>
>
>
>50 : 
>
>
>
>
> Traceback:
> File 
> "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/django/core/handlers/base.py"
>  
> in get_response
>   111. response = wrapped_callback(request, 
> *callback_args, **callback_kwargs)
> File "/home/copser/mineDjango/profiles/views.py" in home
>   7. return render(request, template, context)
> File 
> "/home/copser/.virtualenvs/django17/local/lib/python2.7/site-packages/djang

Re: django Search page

2015-03-06 Thread Collin Anderson
Hi,

You'll need to use javascript for that.

Collin

On Monday, March 2, 2015 at 2:27:35 AM UTC-5, Sabeen Sha wrote:
>
>  which is the best way to implement the following::
> i will be having a text box and a Add button
>
> Along with a table below it containing headers class 
> AssesmentBuildingDetails(models.Model): 
>
>
>  numbuildingid1 = models.CharField(max_length=14,unique=True) 
>
> numbuildingid2 = models.CharField(max_length=7,primary_key=True) 
>
> previous_year = models.CharField(max_length=4, blank=True) 
>
> previous_year_wardname = models.CharField(max_length=100,blank=True, 
> null=True) 
>
> previous_doorno1 = models.CharField(max_length=4,blank=True, null=True) 
>
> previous_doorno2 = models.CharField(max_length=10,blank=True, null=True) 
>
> current_year = models.CharField(max_length=4, blank=True) 
>
> current_year_wardname = models.CharField(max_length=100,blank=True, 
> null=True) 
>
> current_doorno1 = models.CharField(max_length=10,blank=True, null=True) 
>
> current_doorno2 = models.CharField(max_length=10,blank=True, null=True) 
>
> buildingusage = models.CharField(max_length=500,blank=True, null=True) 
>
> ownernameaddressmal = models.CharField(max_length=500,blank=True, 
> null=True) 
>
> ownernameaddresseng = models.CharField(max_length=500,blank=True, 
> null=True) 
>
> plintaarea = models.DecimalField(max_digits=7, 
> decimal_places=2,blank=True, null=True) 
>
> class Meta: 
>
> db_table = 'assesment_building_details' 
>
>
>  
> my logic is to take the numbuildingid2 as input from the text box and when 
> i press enter either on the text field or click the add button it should 
> search through the database
> and add the details to the table without refreshing the whole page. and 
> the clear the textfield and focus on it.
>  It will give proper error msg if the numbuildingid2 is not found
>
> please help how and which is the best way to implement this... 
>
> thanks
>
>
>  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/61e4f0ff-bfd2-45a9-a94d-c80bc0ac5009%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [1.8] MultiHost with template dir per Host

2015-03-06 Thread Collin Anderson
Hi,

You might need to modify the template engine directly.

Collin

On Sunday, March 1, 2015 at 6:31:57 PM UTC-5, Neyoui wrote:
>
> Hi,
>
> I had create a middleware, that is able to change the template directory 
> per host on the fly.
> But it stopped working since I upgraed to Django 1.8 and I tried to fix it.
>
> My problem is:
> If I visit domain1.tld, all works fine. Django loads the templates from 
> the right directory. (/path/domain1.tld/templates/)
> But if I visit now domain2.tld, Django tried to load the template from the 
> domain1.tld directory /path/domain1.tld/templates/ and not from 
> /path/domain2.tld/templates/.
> The debug messages shows me, that the middleware overrides the template 
> path successfully.
>
> Maybe someone can help me to fix it.
>
> Details:
> Django version: 1.8b1
> Python: 3.4
>
> If you need some other information, just ask for it.
>
> - settings.py
>
> MIDDLEWARE_CLASSES = (
> 'core.middleware.MultiHostMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.locale.LocaleMiddleware',
> 'django.middleware.common.CommonMiddleware',
> ...
> )
>
>
> TEMPLATES = [
> {
> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
> 'DIRS': [],
> 'OPTIONS': {
> 'context_processors': [
> 'django.contrib.auth.context_processors.auth',
> 'django.template.context_processors.debug',
> 'django.template.context_processors.i18n',
> 'django.template.context_processors.media',
> 'django.template.context_processors.static',
> 'django.template.context_processors.tz',
> 'django.contrib.messages.context_processors.messages',
> ],
> 'loaders': [
> 'django.template.loaders.filesystem.Loader',
> 'django.template.loaders.app_directories.Loader',
> ],
> 'debug': True
> },
> },
> ]
>
>
> ROOT_URLCONF = 'core.urls'
>
> HOST_MIDDLEWARE_TEMPLATE_DIRS = {
>"domain1.tld": BASE_DIR + "/domain1.tld/templates/",
>"domain2.tld": BASE_DIR + "/domain2.tld/templates/",
> }
>
> HOST_MIDDLEWARE_URLCONF_MAP = {
>"domain1.tld": "domain1.urls",
>"domain2.tld": "domain2.urls",
> }
>
>
> INSTALLED_APPS = (
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'core',
> 'domain1',
> 'domain2',
> )
>
>
> - middleware.py
>
> from django.conf import settings
> from django.utils.cache import patch_vary_headers
>
>
> class MultiHostMiddleware:
>
> def get_settings(self, request):
>
> host = request.META["HTTP_HOST"]
> host_port = host.split(':')
>
> if len(host_port) == 2:
> host = host_port[0]
>
> if host in settings.HOST_MIDDLEWARE_URLCONF_MAP:
>
> urlconf = settings.HOST_MIDDLEWARE_URLCONF_MAP[host]
> template_dirs = settings.HOST_MIDDLEWARE_TEMPLATE_DIRS[host],
>
> else:
> urlconf = settings.ROOT_URLCONF
> template_dirs = None
>
> return urlconf, tuple(template_dirs)
>
> def process_request(self, request):
>
> urlconf, template_dirs = self.get_settings(request)
>
> request.urlconf = urlconf
> settings.TEMPLATES[0]['DIRS'] = template_dirs
>
> def process_response(self, request, response):
>
> if getattr(request, "urlconf", None):
> patch_vary_headers(response, ('Host',))
>
> return response
>
>
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7bdc0770-2606-42c1-b581-1293cae44344%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to save user to foreignKey field for new records in modelFormset case?

2015-03-06 Thread Collin Anderson
Hi,

The form doesn't have access to the current user. I'd attach it using the 
view.

Thanks,
Collin

On Wednesday, February 25, 2015 at 3:53:40 AM UTC-5, Mike wrote:
>
> Hi,
> I have created modelFormset using SchoolHistory model and SchoolForm form.
>
> "SchoolFormSet = modelformset_factory(SchoolHistory, form=SchoolForm)"
>
> I get other content from Form, but should save current user to 
> SchoolHistory model too.
>   
> user=models.ForeignKey(User)
> school_name = models.CharField(max_length = 100)
> rating_average = models.PositiveIntegerField()
>
> I am overriding is_valid or save in order to save user field. 
> My question is how to find current user in model or form level as there is 
> no request parameter available ( request.user).
> request was available in Formset level but I cannot save user to each 
> record there, or could I?
>
> -Thanks
>
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6a149437-2dd6-4d5c-bcce-a304b9fcbcbd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: JSON Response

2015-02-20 Thread Collin Anderson
Hi,

It sounds like you click "submit" and then get a page showing the raw json? 
That sounds like it could be a bug in your code. Either the event handler 
is not connected, or there's an error. You could try checking "Preserve 
Log" in the developer console.

Collin

On Thursday, February 19, 2015 at 5:06:59 PM UTC-5, elcaiaimar wrote:
>
> I mean in a correct form. My code doesn't work. It seems like the JS code 
> doesn't receive the jsonresponse.
> I get a page with {"status":"True","product_id":p.id} But this should be 
> read for the JS code, and if it's True show an alert saying Remove it!
>
> Is there anything wrong in my code? 
>
> El jueves, 19 de febrero de 2015, 21:49:59 (UTC+1), Vijay Khemlani 
> escribió:
>>
>> What do you mean with "in a good way"? Does your code work?
>>
>> On Thu, Feb 19, 2015 at 4:14 PM, elcaiaimar  wrote:
>>
>>> Hello,
>>>
>>> I was wondering how I can send a response JSON in a good way, because I 
>>> have the next code:
>>>
>>> if "product_id" in request.POST:
>>> try:
>>> id_producto = request.POST['product_id']
>>> p = Pozo.objects.get(pk=id_producto)
>>> mensaje = {"status":"True","product_id":p.id}
>>> p.delete() # Elinamos objeto de la base de datos
>>> return JsonResponse(mensaje)
>>> except:
>>> mensaje = {"status":"False"}
>>> return JsonResponse(mensaje)
>>>
>>> And my JS function doesn't work with this code:
>>>
>>>var options = {
>>> success:function(response)
>>> {
>>> if(response.status=="True"){
>>> alert("Eliminado!");
>>> var idProd = response.product_id;
>>> var elementos= $(nombre_tabla+' >tbody >tr').length;
>>> if(elementos==1){
>>> location.reload();
>>> }else{
>>> $('#tr'+idProd).remove();
>>> $(nombre_ventana_modal).modal('hide');
>>> }
>>> }else{
>>> alert("Hubo un error al eliminar!");
>>> $(nombre_ventana_modal).modal('hide');
>>> };
>>> }
>>> };
>>> $(nombre_formulario_modal).ajaxForm(options);
>>> });
>>>
>>> And I don't know what I can do. Does anyone have any idea?
>>>
>>> -- 
>>> 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 http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/2cfc6283-ee2f-4280-b086-2dc1595855c8%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6d1cd6bc-25ce-4c05-907b-312a17feda1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: matplotlib pyplot stop working

2015-02-20 Thread Collin Anderson
Hi,

The freezing could be a memory 
leak. 
http://stackoverflow.com/questions/7125710/matplotlib-errors-result-in-a-memory-leak-how-can-i-free-up-that-memory

Could the image be cached by the browser, does shift+F5 refresh it? The 
easiest way to fix it would be to use a different url/filename every time 
you generate an new image.

Collin

On Thursday, February 19, 2015 at 4:26:16 PM UTC-5, dk wrote:
>
> I am using matplotlib.pyplot to generate a plot image, put it in a temp 
> folder, 
> and then use that to populate a webpage.
>
> the problem is:
> 1) always display the same image,  I all ready deleted the image before 
> creating the new one, 
> I also set pyplot .close()  to close all my figures.
>
> 2) some times everything freeze and stop working.
>
> my suspicions is since django is constantly running keeps the figure in 
> the memory some how.   have any one got issues like this?
> thanks.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d4f25a28-67f3-445e-8b46-f01b026842a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to host django application in redhat using virtual environment?

2015-02-20 Thread Collin Anderson
Hi,

Here's a tutorial.

https://devops.profitbricks.com/tutorials/deploy-django-with-virtualenv-on-centos-7/

Collin

On Thursday, February 19, 2015 at 8:29:47 AM UTC-5, SHINTO PETER wrote:
>
> How to host django application in redhat using virtual environment?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ec55fd10-4962-4ca1-9305-2127e470511f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Seems like a geodjango bug with multiple databases

2015-02-19 Thread Collin Anderson
Hi,

Interesting. What version of django is this?

Here's something to try:
Room.objects.using('another').select_related('hotel').get(pk=10)

It could very well be an issue with GeoManager / GeoQuerySet.

You also could ask on the geodjango list to see if anyone else has run into 
that.

http://groups.google.com/group/geodjango

Collin

On Wednesday, February 18, 2015 at 9:45:15 AM UTC-5, Luan Nguyen wrote:
>
> I'm using geodjango and multiple databases, and experiencing a quite weird 
> situation, I guess it's a kind of bug but not absolutely sure since I'm 
> pretty new to Django.
>
> Here is how to reproduce the problem:
> - Set up another database besides default:
> DATABASES = {
> 'default': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> ,
> 'NAME' : 'issue1',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> 'another': {
> 'ENGINE' : 'django.contrib.gis.db.backends.postgis' 
> ,
> 'NAME' : 'issue2',
> 'USER' : 'user',
> 'PASSWORD' : 'password',
> 'HOST' : '127.0.0.1',
> 'OPTIONS' : {
> 'autocommit' : True,
> }
> },
> }
>
> And two models:
> from django.db import models as default_models
> from django.contrib.gis.db import models
> # Create your models here.
> class Hotel(models.Model):
> hotel_name = models.CharField(max_length=255)
> objects = models.GeoManager()
>
> class Room(models.Model):
> room_num = models.IntegerField()
> hotel = models.ForeignKey(Hotel, null=True, blank=True)
>
> Add data into issue2 database (leave issue1 blank), then go into shell:
> >>>h = Hotel.objects.using('another').all()[0]
> >>> h.id
> 9
> >>>h.room_set.all()[0].id #=> room id 10 links to hotel id 9
> 10
> >>>r = Room.objects.using('another').get(pk=10)
> >>>r.hotel
> Traceback (most recent call last):
> File "", line 1, in 
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/fields/related.py
>  
> ",
>  
> line 572, in __get__
> rel_obj = qs.get()
> File "/
> Applications/MAMP/htdocs/Rainmaker/vir341/lib/python3.4/site-packages/django/db/models/query.py
>  
> ",
>  
> line 357, in get
> self.model._meta.object_name)
> multi.models.DoesNotExist: Hotel matching query does not exist.
>
> The thing is, if I create a hotel record on database issue1 with id of 9 
> then the last command works, so I guess it tried to look up in default 
> database. This doesn't have any problems if I use default manager for 
> Hotel, so I guess it's a bug?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/64d0f22e-ce10-4626-beef-5f99c63de787%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Trouble changing from sqlite3 to postgres

2015-02-19 Thread Collin Anderson
Hi,

It seems strange that it would be trying to convert a "date" column to an 
integer.

Since you're creating a new database from scratch, you could try deleting 
your migrations and generating them from scratch to see if that helps.

Otherwise, what does your "app_1.0003_auto_20141126_2333" file have for 
operations?

Collin

On Tuesday, February 17, 2015 at 9:22:30 PM UTC-5, tony@gmail.com wrote:
>
> The error occurs during migration.
> The following shows the complete traceback.
> Thanks.
> 
> % python manage migrate
> WFK: BASE_DIR= /home/bill/django/wfkprojs/proj1
> WFK: STATIC_PATH= /home/bill/django/wfkprojs/proj1/app_1/static/
> WFK: MEDIA_ROOT= /home/bill/django/wfkprojs/proj1/app_1/media_root/
> WFK: MEDIA_URL= /media_root/
> Operations to perform:
>   Apply all migrations: contenttypes, app_1, sessions, auth, admin
> Running migrations:
>   Applying app_1.0003_auto_20141126_2333...Traceback (most recent call 
> last):
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/backends/utils.py", line 
> 65, in execute
> return self.cursor.execute(sql, params)
> psycopg2.ProgrammingError: column "date" cannot be cast automatically to 
> type integer
> HINT:  Specify a USING expression to perform the conversion.
>
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/core/management/__init__.py", 
> line 385, in execute_from_command_line
> utility.execute()
>   File 
> "/usr/local/lib/python3.3/site-packages/django/core/management/__init__.py", 
> line 377, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/core/management/base.py", 
> line 288, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/core/management/base.py", 
> line 338, in execute
> output = self.handle(*args, **options)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/core/management/commands/migrate.py",
>  
> line 160, in handle
> executor.migrate(targets, plan, fake=options.get("fake", False))
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/migrations/executor.py", 
> line 63, in migrate
> self.apply_migration(migration, fake=fake)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/migrations/executor.py", 
> line 97, in apply_migration
> migration.apply(project_state, schema_editor)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/migrations/migration.py", 
> line 107, in apply
> operation.database_forwards(self.app_label, schema_editor, 
> project_state, new_state)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/migrations/operations/fields.py",
>  
> line 139, in database_forwards
> schema_editor.alter_field(from_model, from_field, to_field)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/backends/schema.py", line 
> 473, in alter_field
> self._alter_field(model, old_field, new_field, old_type, new_type, 
> old_db_params, new_db_params, strict)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/backends/schema.py", line 
> 626, in _alter_field
> params,
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/backends/schema.py", line 
> 99, in execute
> cursor.execute(sql, params)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/backends/utils.py", line 
> 81, in execute
> return super(CursorDebugWrapper, self).execute(sql, params)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/backends/utils.py", line 
> 65, in execute
> return self.cursor.execute(sql, params)
>   File "/usr/local/lib/python3.3/site-packages/django/db/utils.py", line 
> 94, in __exit__
> six.reraise(dj_exc_type, dj_exc_value, traceback)
>   File "/usr/local/lib/python3.3/site-packages/django/utils/six.py", line 
> 549, in reraise
> raise value.with_traceback(tb)
>   File 
> "/usr/local/lib/python3.3/site-packages/django/db/backends/utils.py", line 
> 65, in execute
> return self.cursor.execute(sql, params)
> django.db.utils.ProgrammingError: column "date" cannot be cast 
> automatically to type integer
> HINT:  Specify a USING expression to perform the conversion.
>
>
> On Tuesday, February 17, 2015 at 4:39:27 PM UTC-8, Joel Burton wrote:
>>
>> The error is probably in code you wrote that uses the date field. Can you 
>> post the full traceback? That will let us see where the caller was that 
>> created the problem.
>>
>> On Tuesday, February 17, 2015 at 3:13:30 PM UTC-5, tony@gmail.com 
>> wrote:
>>>
>>> I have written a simple Django app (my first) that works with sqlite3 
>>> database.
>>> I want to change to postgres, but when I run the Django 1.7 migration 
>>> utility  with the comman

Re: Form Wizard: how to send instance_dict based on the request

2015-02-19 Thread Collin Anderson
Hi,

You could instead just override get_form_instance(step). That way you'll 
have access to self.request.

Collin

On Tuesday, February 17, 2015 at 8:26:30 PM UTC-5, Karim Gorjux wrote:
>
> Hello mates!
>
> I have some problems to understand how to set the view for 
> the NamedUrlSessionWizardView creating a instance_dict based on the user in 
> the request.
>
> in my urls.py
>
> url(r'wizard/new/(?P.+)/$',
> ServiceCUWizard.as_view(
>FORMS,   # the list of ['form_name', form_object]
>url_name='service:new_wizard_step',
>done_step_name='finished',
> ), name='new_wizard_step'),
>
> It works, I got all the forms as expected.
>
> The forms are modelforms and I would like to bound the instance if is 
> possible, but I can populate it only using the request. I think I could do 
> that subclassing def __init__, but the instance_dict is a class attribute, 
> how I can populate it?
>
> Thnak you
>
>
>
> -- 
> Karim N. Gorjux
>  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c7e931b5-1671-4570-be34-6894fc97c43c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can migrated apps depend on unmigrated apps?

2015-02-19 Thread Collin Anderson
Hi Carsten,

I in my experience, it _sometimes_ works to have migrated apps depend on 
unmigrated apps.

If you haven't yet, you could try generating migrations for the unmigrated 
app, and reference them using MIGRATION_MODULES.

Collin

On Tuesday, February 17, 2015 at 5:00:26 PM UTC-5, Carsten Fuchs wrote:
>
> Hi Michael, 
>
> Am 17.02.2015 um 22:44 schrieb Michael Pöhn: 
> > This is all covered in Djangos documentation... 
> > https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies 
>
> Well, no... please see below. 
>
> > Let me paste the relevant parts for you: 
> > 
> > »Be aware, however, that unmigrated apps cannot depend on migrated apps, 
> [...]« 
>
> This explains that unmigrated apps cannot depend on migrated apps. 
>
> My question is about the opposite case: Can migrated apps depend on 
> unmigrated apps? I've explained the apparent problem in greater detail 
> in my original post. 
>
> Best regards, 
> Carsten 
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6ea03841-50de-413d-9f7c-5769b497b550%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Handling FormSet client side with javascript

2015-02-19 Thread Collin Anderson
Hi,

Sorry for the late reply. Does simply using {{ formset.media }} work?

Collin

On Friday, February 13, 2015 at 11:02:31 AM UTC-5, aRkadeFR wrote:
>
> Hello everyone, 
>
> I'm using FormSet in order to add multiple object at once on 
> a view. To have a more user friendly approach, I created a 
> 'my.formset.js' file and I need to include a 'jquery.formset.js' lib 
> to add/remove row of the formset (client side) and edit the 
> formset management information. 
>
> My idea to resolve this problem was to include these two 
> javascript media file everytime I'm using a formset. 
>
> A bit like every media js file for widgets :) 
>
> So my first attempt was something like that: 
> ``` 
> class BaseFormSet(BaseInlineFormSet): 
>  class Media: 
>  js = ("my.formset.js", "jquery.formset.js", ) 
> ``` 
>
> but this doesnt render these js files with formset.media.render_js(). 
>
> My second attempt was: 
> ``` 
> formset.media.add_js( ["my.formset.js", "jquery.formset.js", ]) 
> ``` 
>
> My last attempt: 
> ``` 
> form = formset.forms[0] 
> formset.forms[0].fields[form.fields.keys()[0]].media.add_js(["my.formset.js", 
>
> "jquery.formset.js", ]) 
> ``` 
>
> Still not working cause the .media._js is regenerating the media js 
> files. 
>
> The only solution so far I have, provided by @tbaxter, is to 
> include all my js files in all my application, and initialize/use 
> the formset/widgets javascript only on certain condition. 
>
> I don't like the idea of including my js application wide. It's 
> gonna overload all my pages for nothing (my js files are 
> completely standalone) when there is no FormSet. 
>
> Can I have your tought on this probleme, and what solution 
> you have in mind? 
>
> Thank you, 
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eb5af3a3-d09f-4562-b290-fec7f763e74e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: JsonResponse and Ajax function.

2015-02-19 Thread Collin Anderson
Hi,

Sorry for the late reply. Do you need to use JSON.parse(response).status?

Collin

On Tuesday, February 10, 2015 at 8:33:58 AM UTC-5, elcaiaimar wrote:
>
> Hello!
>
> I've written a code to delete db registers and I want to call an ajax 
> function when the delete is done.
> At the moment, when I click my delete button I only receive a message: 
> {"status":"True","product_id":p.id} or {"status":"False"} 
> and this should be sent to the ajax function and I shoud have an alert 
> saying to me: product has been removed.
> I don't know why, probably there is something wrong in the relation of my 
> JsonResponse and ajax function.
>
> I put my code below. Does anybody know how can I fix this?
> Thank you very much!
>
> *template*:
>
>  
>   {% csrf_token %}
>   
>aria-hidden="true">Cerrar button>
>   Eliminar
>  
>
> *views.py:*
>
> if request.method=="POST":
> if "product_id" in request.POST:
> try:
> id_producto = request.POST['product_id']
> p = Pozo.objects.get(pk=id_producto)
> mensaje = {"status":"True","product_id":p.id}
> p.delete() # Elinamos objeto de la base de datos
> return JsonResponse(mensaje)
> except:
> mensaje = {"status":"False"}
> return JsonResponse(mensaje)
>
>
>
> *Ajax.js:*// Autor: @jqcaper
> // Configuraciones Generales
> var nombre_tabla = "#tabla_productos"; // id
> var nombre_boton_eliminar = ".delete"; // Clase
> var nombre_formulario_modal = "#frmEliminar"; //id
> var nombre_ventana_modal = "#myModal"; // id
> // Fin de configuraciones
> $(document).on('ready',function(){
> $(nombre_boton_eliminar).on('click',function(e){
> e.preventDefault();
> var Pid = $(this).attr('id');
> var name = $(this).data('name');
> $('#modal_idProducto').val(Pid);
> $('#modal_name').text(name);
> });
> var options = {
> success:function(response)
> {
> if(response.status=="True"){
> alert("Eliminado!");
> var idProd = response.product_id;
> var elementos= $(nombre_tabla+' >tbody >tr').length;
> if(elementos==1){
> location.reload();
> }else{
> $('#tr'+idProd).remove();
> $(nombre_ventana_modal).modal('hide');
> }
> }else{
> alert("Hubo un error al eliminar!");
> $(nombre_ventana_modal).modal('hide');
> };
> }
> };
> $(nombre_formulario_modal).ajaxForm(options);
> });
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/a798d66d-b9eb-4698-98fe-8944362b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django: get profiles having auth.Group as foreign key

2015-02-19 Thread Collin Anderson
Hi,

Sorry for the late reply. Do you just want something like this?

{% for dashboard in group.dashboard_set.all %}
 {{ dashboard.d_name }}
 etc
{% endfor %}

Collin

On Tuesday, February 10, 2015 at 12:41:15 AM UTC-5, itsj...@gmail.com wrote:
>
> I have an model which uses auth.models Group as foreign key called 
> Dashboard:-
>
> 
>
> 
>
> class Dashboard(models.Model):
> d_name = models.CharField(max_length=200)
> d_description = models.CharField(max_length=200)
> d_url = models.CharField(max_length=200)
> d_status = models.CharField(max_length=200)
> owner = models.ForeignKey(Group)
> 
> def __str__(self):return self.d_name
>
> 
>
> my views.py is:-
>
> 
>
> 
>
> def custom_login(request):
> if request.user.is_authenticated():
> return HttpResponseRedirect('dashboards')
> return login(request, 'login.html', authentication_form=LoginForm)
>
> def custom_logout(request):
> return logout(request, next_page='/')
>
> def user(request):
> context = {'user': user, 'groups': request.user.groups.all()}
> return render_to_response('registration/dashboards.html', context, 
> context_instance=RequestContext(request))
>
> 
>
> and here using this dashboards.html i want to display the dashboards by 
> using the Group_name which i will get as a result of **group.name** :-
>
> 
>
> 
>
> {% extends "base.html" %}
> {% block content %}
> {% if user.is_authenticated %}
> Welcome, {{ request.user.get_username }}. 
> {% else %}
> Welcome, new user. Please log in.
> {% endif %}
>
> 
> {% for group in groups %}
> 
> {{ group.name }} -
> 
> {{ dashboards.d_name }}{% if not forloop.last %},{% endif 
> %}
> 
> 
> {% endfor %}
> 
>
>
>
> {% endblock %}
>
> 
>
> here i have mentioned all the supporting information for my problem, 
> please let me know if there are any solution.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/03466a23-b48a-45e8-8a1f-eeda1c23701b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom model field and custom widget

2015-02-19 Thread Collin Anderson
Hi,

Sorry for the late reply. Check out editable=False if you haven't.

Collin

On Friday, January 30, 2015 at 9:03:41 AM UTC-5, Thomas Weholt wrote:
>
> Hi,
>
> I need to create a custom django model field, a varchar(10) field which 
> has a calculated value set on save on the model using it and then never 
> changed. This should happen automatically. This field should appear as 
> hidden or read-only in forms and it would be nice to handle the render 
> output if the field is accessed in templates. The calculated value 
> generated on save must access the database and look into a seperate table 
> to calculate its value, ie. I need to control the generation of the value 
> it gets.
>
> Any ideas or hints?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2195b874-bab4-4d0c-b13e-a9a144d1348b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to detect (daily) User Login when using cookies?

2015-01-30 Thread Collin Anderson
Hi,

If you use a custom authentication backend, you could update it every time 
get_user(request) is called.

Collin

On Wednesday, January 28, 2015 at 4:58:30 AM UTC-5, Tobias Dacoir wrote:
>
> Yes that would be enough. I know in the User Model there is last_login but 
> that is only updated when the User actually logs in. And the signal from 
> django-allauth is also only send when the user uses the login form. The 
> only other alternative I found was to check in every view I have for 
> request.user and store / update datetime.now. But this is quite ugly.
>
>
> On Tuesday, January 27, 2015 at 9:00:15 PM UTC+1, Collin Anderson wrote:
>>
>> Hi,
>>
>> Would it make sense to simply keep a record of when the last time you've 
>> seen the user is?
>>
>> Collin
>>
>> On Friday, January 23, 2015 at 4:43:41 AM UTC-5, Tobias Dacoir wrote:
>>>
>>> I'm using django-allauth and I receive a signal when a user logs in. Now 
>>> I want to store each day the user logs in. However, when the user does not 
>>> logout he can still log in the next day thanks to the cookies. I know that 
>>> I can set SESSION_EXPIRE_AT_BROWSER_CLOSE to True in settings.py. But this 
>>> may annoy some Users. 
>>>
>>> So is there a way to use cookies but still tell if a User has accessed 
>>> the site for the first time today?
>>>
>>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d2d6d493-2c95-43c1-a1ae-c08b9e0fbea4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Reduce start up time for manage.py

2015-01-30 Thread Collin Anderson
Hi,

Many people would recommend against this, but if you can put the imports 
for your heavy 3rd party libraries inside functions and methods, that allow 
them to be loaded only if needed.

I would also recommend in general to simply have fewer libraries and apps 
(easier said than done :)

Also, is it slow only for the first load, or are repeated loads slow too?

I hope you aren't doing database queries or other expensive calls on 
startup.

Try putting this at the top of your manage.py to see more of what's going on

import logging; logging.basicConfig(level=logging.DEBUG)

Collin

If you want some benchmarks, here are some of my websites
221243 function calls (214987 primitive calls) in 0.394 seconds
448659 function calls (437433 primitive calls) in 0.611 seconds 
698349 function calls (687730 primitive calls) in 0.749 seconds

On Wednesday, January 28, 2015 at 4:42:09 AM UTC-5, chj wrote:
>
> Hi,
>
> I'm having a quite large Django project with dozens of apps and many 
> reusable third-party libraries. All the custom management commands (being 
> used with manage.py ) take a long time to be executed, since the 
> start up sequence takes between 3 and 5 seconds. Using the cProfile module 
> I was able to see that quite a lot of function calls are executed and it 
> looks like that every app is loaded, including its libraries and such 
> before the actual management command is executed. Is there any common way 
> to speed that up (e.g. by not loading apps/libraries that are not required 
> for a specific management command)? Django 1.7+ is used on Python 3.4.
>
> Output from `python3 -m cProfile manage.py` (truncated): 1100697 function 
> calls (1064507 primitive calls) in 5.172 seconds
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0ac3ca3d-78a5-49bf-be96-05bc0017bf40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best practice to render the view based on the user

2015-01-30 Thread Collin Anderson
Hi,

Not sure about whether it's a good idea or not. If statements might also be 
good enough.

Be careful with security, but in theory something like this should work:

method_name = 'person' + person.type
method = getattr(self, method_name)
output = method()

Collin

On Wednesday, January 28, 2015 at 12:04:06 AM UTC-5, Karim Gorjux wrote:
>
> Hi! I would like to render views based on the user. I have some differents 
> type of users on my app and I would like to create a class like this one 
> for the view:
>
> class MyView(MyCustomView)  # MyCustomView subclass View 
>
> def __init__(self, *args, **kwargs):
> # common code for all persons
>
> def personA(self):
> # code for personA
>
> def personB(self):
> # code for personA
>
> # 
>
> def personN(self):
> # code for personA
>
> def anyPerson(self)
> # For any user non listed above
> 
>
> Then if the MyView is run, the function based on the user is automatically 
> fired.
>
> My doubts (at the moment):
>
> 1) Do you think is the a good way to face the problem?
>
> 2) I have methods in the models to know what person is logged. How I can 
> automatically load the right function in the class based on the user?
>
> Thank you
>
> -- 
> Karim N. Gorjux
>  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7c787485-1566-4aaf-af91-be853337e107%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django / tastypie - how to exclude a resource attribute from obj_create, but keep it for listing

2015-01-30 Thread Collin Anderson
Hi Eugene,

Would it work to something like this in your obj_create?
bundle.data.pop('blueprint', None)

Collin

On Tuesday, January 27, 2015 at 11:01:56 AM UTC-5, Eugene Goldberg wrote:
>
>   I have the following tastypie resource:
>
>  class WorkloadResource(ModelResource):
> # blueprints = ManyToManyField(Blueprint, 'blueprints')
> blueprint = fields.OneToManyField('catalog.api.BlueprintResource', 
> attribute='blueprint',
>  related_name='workloads', full=True, 
> null=True)
>
> def obj_create(self, bundle, request=None, **kwargs):
> # return super(WorkloadResource, self).obj_create(bundle, request, 
> **kwargs)
> return super(WorkloadResource, self).obj_create(bundle, 
> request=request, **kwargs)
>
> def obj_update(self, bundle, request=None, **kwargs):
>
> workload = Workload.objects.get(id=kwargs.get("pk"))
> workload.description = bundle.data.get("description")
> workload.name = bundle.data.get("name")
> workload.image = bundle.data.get("image")
> workload.flavor = bundle.data.get("flavor")
> workload.save()
>
> def obj_delete(self, bundle, **kwargs):
>
> return super(WorkloadResource, self).obj_delete(bundle)
>
> def determine_format(self, request):
> return 'application/json'
>
> class Meta:
> queryset = Workload.objects.all()
> resource_name = 'workload'
> authorization=Authorization()
> filtering = {
> "blueprint": ('exact', ),
> }
>
>
>  When I use curl to POST: 
>
>  curl -i -H "Content-Type: application/json" -X POST -d 
>  @wkl.json  http://localhost:8000/api/workload/
>
>  where wkl.json is:
>
>  { "name":"w 5", "description":"w 5 desc" }
>
>
>  I get this error:
>
>  AttributeError: 'Workload' object has no attribute 'blueprint'
>
>  I do need to have this attribute, so I can list all child workloads for a 
> given blueprint 
>  like this:  GET /api/workload/?blueprint=1
>
>  but I need to exclude this 'blueprint' attribute from participating in 
> the obj_create
>
>  What is the proper place and syntax to do this?
>
>
> -Eugene
>
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7940ec09-b130-43ab-ab43-c25a26466284%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: path to django from jython

2015-01-30 Thread Collin Anderson
Hi,

I think you to make sure django is on your PYTHONPATH / sys.path

Collin

On Tuesday, January 27, 2015 at 10:51:13 AM UTC-5, Josh Stratton wrote:
>
> Okay, stupid question, but how do I source django when jusing jython?  I 
> have django installed using pip and jython installed locally.  I've built 
> my project using python and after adding "doj" to the installed apps, I get 
> a path error building a war.  
>
> $ jython manage.py buildwar
> Traceback (most recent call last):
>   File "manage.py", line 8, in 
> from django.core.management import execute_from_command_line
> ImportError: No module named django
>
> https://pythonhosted.org/django-jython/war-deployment.html
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1d542d5c-07ed-46c0-ad6d-4fc3bab8e29e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Create Django token-based Authentication

2015-01-30 Thread Collin Anderson
Hi,

What happens when you try? :)

Your setup is pretty complicated, but I don't know if REST framework will 
help much.

Collin

On Tuesday, January 27, 2015 at 12:00:59 AM UTC-5, Hossein Rashnoo wrote:
>
> I have my authentication service on django. I want to role as web-service 
> to gave other website a token and authenticate users with that token.
>
> This is my scenario:
>
>1. user visit external website and try to login
>2. when hit the login button that website redirect user to my site to 
>use username and password for login
>3. When successfully logged in users will redirect to external website 
>with a token
>4. And every time that website send me that token, I recognize that 
>user and pass some data to external website I'm try to use REST-Framework 
>authentication but it is too complicated Please help me.
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cc8def1e-9788-41ef-8896-4632b0d3b1ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Putting picture thumbnails within admin page

2015-01-29 Thread Collin Anderson
Hi,

Any luck?

Try looking at the Network tab of the developer console to see what the 
errors are.

Collin

On Monday, January 26, 2015 at 7:31:54 PM UTC-5, bradford li wrote:
>
>
> I am trying to put thumbnail pictures of my photos within my admin page. I 
> am currently running into the issue where the thumbnail isn't displayed, 
> when I click on thumbnail I am redirected to the homepage of my project 
> with this as the URL: 
>
> http://127.0.0.1:8000/media/tumblr_ngotb4IY8v1sfie3io1_1280.jpg
>
> Here is a gist of my code: 
>
> https://gist.github.com/liondancer/678752e8bf31cc7d2c63
>
> Stackoverflow question:
>
>
> http://stackoverflow.com/questions/28159740/configuring-admin-to-display-thumnails
>
> If anything else is needed please let me know! 
>
>
>
> 
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d0302752-6a77-4d67-89da-f9bd27178ab1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Wanted: Best practices for setting "_" (to ugettext/ugettext_lazy)

2015-01-27 Thread Collin Anderson
Hi,

Why reset it at the end of your module?

Why not use ugettext_lazy everywhere?
from django.utils.translation import ugettext_lazy as _

(Disclaimer: I've never used translations before :)

Collin

On Saturday, January 24, 2015 at 3:46:31 AM UTC-5, Torsten Bronger wrote:
>
> Hallöchen! 
>
> This is not about where to use ugettext/ugettext_lazy.  I know 
> that.  :-) 
>
> But I was fed up with all those "_ = ugettext" scattered in my code 
> and tried to find a more systematic approach.  The following test 
> program runs through: 
>
> ugettext = lambda x: x 
> ugettext_lazy = lambda x: x 
>
> _ = ugettext_lazy 
>
> def function(): 
> assert _ == ugettext 
>
> class A(object): 
> assert _ == ugettext_lazy 
>
> def method(self): 
> assert _ == ugettext 
>
> assert _ == ugettext_lazy 
>
> assert _ == ugettext_lazy 
>
> def function_b(): 
> assert _ == ugettext 
>
> _ = ugettext 
>
>
> function() 
> function_b() 
> a = A() 
> a.method() 
>
> Do you think this is a good idea?  Simply setting _ to 
> ugetttext_lazy at the beginning of a module and to ugettext at the 
> end (and dealing with the very few remaining exceptions)?  How do 
> you do that? 
>
> Tschö, 
> Torsten. 
>
> -- 
> Torsten BrongerJabber ID: torsten...@jabber.rwth-aachen.de 
>  
>   or http://bronger-jmp.appspot.com 
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/021586ad-9efd-4c31-949a-ed6f15fbf03b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: gis: geo_db_type error in run_checks() in 1.7 (not 1.6)

2015-01-27 Thread Collin Anderson
Hi,

You could also try the geodjango mailing list if nothing else.
http://groups.google.com/group/geodjango

Collin

On Sunday, January 25, 2015 at 6:04:57 PM UTC-5, dne...@destinati.com wrote:
>
> Hi,
>
> Wanted to throw this out there, not sure truly if it is my fault or a bug.
>
> Just upgraded from (python 2.6.x, django 1.6) to (python 2.7.x, django 
> 1.7).
> If I invoke manage.py on any subcommand, I get an error as follows:
>
> 
> [app_dev]$ python2.7 manage.py sql
> Traceback (most recent call last):
>   File "manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", 
> line 385, in execute_from_command_line
> utility.execute()
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", 
> line 377, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", 
> line 288, in run_from_argv
> self.execute(*args, **options.__dict__)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", 
> line 337, in execute
> self.check()
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", 
> line 371, in check
> all_issues = checks.run_checks(app_configs=app_configs, tags=tags)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/checks/registry.py", 
> line 59, in run_checks
> new_errors = check(app_configs=app_configs)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/core/checks/model_checks.py", 
> line 28, in check_all_models
> errors.extend(model.check(**kwargs))
>   File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", 
> line 1046, in check
> errors.extend(cls._check_fields(**kwargs))
>   File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", 
> line 1122, in _check_fields
> errors.extend(field.check(**kwargs))
>   File 
> "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py" 
> , line 192, in check
> errors.extend(self._check_backend_specific_checks(**kwargs))
>   File 
> "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py" 
> , line 290, in _check_backend_specific_checks
> return connection.validation.check_field(self, **kwargs)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/db/backends/mysql/validation.py",
>  
> line 23, in check_field
> field_type = field.db_type(connection)
>   File 
> "/usr/local/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py",
>  
> line 221, in db_type
> return connection.ops.geo_db_type(self)
> AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'
> 
>
> In mysql/validation.py in Django 1.7 it attempts 'field_type = 
> field.db_type(connection)'. This call isn't made in the same function in 
> Django 1.6, so this problem doesn't arise. If I add this call into the 
> Django 1.6 function the same error appears.
>
> Something to do with the fact that connection.ops is  'django.db.DefaultConnectionProxy'>. 'django.db.backends.mysql.base.DatabaseOperations'> so it isn't correctly 
> getting to contrib/gis/db/backends/mysql/operations.py (?).
>
> This error occurs for a PointField field (not sure about any others), e.g. 
> a model of the type:
>
> ---
> from django.contrib.gis.db import models class MyModel(models.Model):
> point_xy = models.PointField()
> objects = models.GeoManager()
> ---
>
> CentOS release 6.6 (Final)
> geos.x86_64 3.3.2-1.el6
> mysql.x86_645.1.73-3.el6_5
> Django (1.7.3)
> Python 2.7.9
> MySQL-python (1.2.5)
>
> I fixed this with a hack (avoid the db_type call based on the few field 
> names I use for PointField's), but perhaps this should be looked into.
>
> Dylan Nelson
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c9508757-e433-4d33-9b30-e81c44e37fc7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Forms test run on development database instead of test database

2015-01-27 Thread Collin Anderson
Hi,

I just tried out your project. Looking at the stacktrace, the test module 
is importing forms (before the test starts). The forms module is running a 
query on startup for choices.

https://github.com/merwan/django-choicefield/blob/master/myapp/forms.py

Don't do queries on startup. :)

Collin

On Monday, January 26, 2015 at 7:07:54 AM UTC-5, Merouane Atig wrote:
>
> Hi,
>
> I have a strange issue with a forms test and I would like to know if I'm 
> doing something wrong or if it is a Django bug.
>
> I created a repo to reproduce the issue I have: 
> https://github.com/merwan/django-choicefield
>
> I have a DomainForm class with a choice field populated from a table in 
> the database. I'm trying to test it using the Django testing tools, but I 
> get the error "django.db.utils.OperationalError: no such table: 
> myapp_topleveldomain" (see the README in the Github repo for the full stack 
> trace).
>
> If I first create my development database and migrate it, then I do not 
> have any error. I expected that the test would run on the test database but 
> it is not the case.
>
> My test environment should work properly as I also created a model test 
> which runs correctly on the test database and do not need the development 
> database.
>
> Can you tell me what would be the proper way to write this test so that it 
> runs on the test database? Is it a bug with the Django testing tools or am 
> I doing something wrong when populating my ChoiceField?
>
> I'm using Django 1.7.3 and Python 3.4.0
>
> Thanks for your help
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc9f47cb-cd64-4607-afe1-12f86e492034%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: sending email

2015-01-27 Thread Collin Anderson
Hi,

You should be able to figure out which box is checked from 
form.cleaned_data.

Collin

On Sunday, January 25, 2015 at 11:53:12 PM UTC-5, suabiut wrote:
>
> Hi Collin,
> Thank you very much for your help. its works perfectly.
> The next thing i want to do is to send an email to a specific user that i 
> select on a table. when an authorized user select a user to approve his or 
> her leave i want an email to be send to the user. so basically when i click 
> on the checkbox on the Test User form the table below. i should get a form 
> to approve the leave as below. now when i click on authorized Leave button 
> an email should be send to the test user. please point me to right 
> direction.
>  [image: Inline image 1]
>
> [image: Inline image 2]
>
> Cheers,
>
> On Fri, Jan 23, 2015 at 1:18 PM, Collin Anderson  > wrote:
>
>> Hi,
>>
>> Just query the users you want.
>>
>> to_emails = [u.email for u in 
>> User.objects.filter(username__in=['person1', 'person2', 'person3'])]
>> send_mail('Subject here', 'Here is the message.', from_email_address, 
>> to_emails)
>>
>> Collin
>>
>> On Wednesday, January 21, 2015 at 11:29:51 PM UTC-5, suabiut wrote:
>>>
>>> Thanks,
>>> I am trying to send email to the users that their email address is 
>>> stored in the database on the auth_user table. can someone please point me 
>>> to the right direction.
>>>
>>> Cheers,
>>>
>>>
>>> On Thu, Jan 22, 2015 at 3:03 PM, Collin Anderson  
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> Yes, this is possible. Something like:
>>>>
>>>> from django.core.mail import send_mail
>>>>
>>>> def authorized_leave(request):
>>>> form = MyForm()
>>>> if request.method == 'POST':
>>>> form = MyForm(request.POST)
>>>> if form.is_valid():
>>>> obj = form.save()
>>>> send_mail('Subject here', 'Here is the message.', '
>>>> fr...@example.com', ['t...@example.com'])
>>>> return redirect('/done/')
>>>> return render(request, 'template.html', {form: 'form'})
>>>>
>>>> Collin
>>>>
>>>>
>>>> On Monday, January 19, 2015 at 10:02:45 PM UTC-5, suabiut wrote:
>>>>>
>>>>> Hi,
>>>>> I am trying to send an email to several users once a form is submit. I 
>>>>> have done the view.py to update the database once the form is submitted 
>>>>> and 
>>>>> is working fine. what i want to accomplish when the form is submitted is 
>>>>> to 
>>>>> update the database and at the same time send out email when a user click 
>>>>> on the Authorized leave button.
>>>>>
>>>>> here is the step i want to do:
>>>>>
>>>>>  [image: Inline image 1]
>>>>>
>>>>> 1) user click on the check box and this form below appears
>>>>>
>>>>>
>>>>> [image: Inline image 2]
>>>>>  2) the user then fill up the form and click on authorized leave 
>>>>> button. the form will stored the information into the database. which i 
>>>>> have already done it. what i wanted to do next is to also send a emails 
>>>>> when the authorized leave button is click. is it possible to send emails 
>>>>> and also save data to database when the authorized leave button is click. 
>>>>> i 
>>>>> want to send email to the *Test User* which have his email address 
>>>>> store in the database. 
>>>>>
>>>>> template.html
>>>>> {%csrf_token%}
>>>>> 
>>>>> {{form.as_table}}
>>>>> 
>>>>> 
>>>>>   
>>>>>
>>>>>
>>>>> 
>>>>>
>>>>> please point me to the right direction.
>>>>>
>>>>> Cheers,   
>>>>>
>>>>>   -- 
>>>> 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, 

Re: programming error in group by clause

2015-01-27 Thread Collin Anderson
Hi,

What database are you using?

If you can reproduce this in a simple project, feel free to open a ticket 
about it.

Thanks,
Collin

On Sunday, January 25, 2015 at 12:51:31 AM UTC-5, satya wrote:
>
> Need some help on fixing the following error. I recently moved to 1.8alpha 
> version from an older version django-e9d1f11 and I started seeing this 
> error. Looks like the way group by is constructed has changed.
>
> Here is the model that I have.
>
> class everydaycost(models.Model):
> cost = models.DecimalField(max_digits=20, decimal_places=2)
> rev = models.DecimalField(max_digits=20, decimal_places=2)
> ts = models.DateField(db_index=True)
>
> I am trying to get roi (rev/cost) for each day of week.
>
> $ python manage.py shell
> Python 2.7.5 (default, Mar  9 2014, 22:15:05)
> [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
> >>>
> >>> from testgroupby.models import *
> >>> from django.db.models import Q, Count, Min, Sum, Func, FloatField
> >>> qs = everydaycost.objects.all()
> >>> qs = qs.extra(select={'dow': "TO_CHAR(ts, 'D')"})
> >>> qs = qs.values('dow')
> >>> qs = qs.annotate(sum_cost=Sum('cost'))
> >>> qs = qs.annotate(sum_rev=Sum('rev'))
> >>> qs = qs.annotate(roi=Func(A='CAST(Sum("rev") as numeric)', 
> B='CAST(Sum("cost") as numeric)',
> ... template='ROUND(COALESCE(%(A)s / NULLIF(%(B)s,0), 0), 
> 2)', output_field=FloatField()))
> >>> print qs
> DEBUG(0.002) SELECT (TO_CHAR(ts, 'D')) AS "dow", 
> SUM("testgroupby_everydaycost"."cost") AS "sum_cost", 
> SUM("testgroupby_everydaycost"."rev") AS "sum_rev", 
> ROUND(COALESCE(CAST(Sum("rev") as numeric) / NULLIF(CAST(Sum("cost") as 
> numeric),0), 0), 2) AS "roi" FROM "testgroupby_everydaycost" GROUP BY 
> (TO_CHAR(ts, 'D')), ROUND(COALESCE(CAST(Sum("rev") as numeric) / 
> NULLIF(CAST(Sum("cost") as numeric),0), 0), 2) LIMIT 21; args=()
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/Downloads/Django-1.8a1/django/db/models/query.py", line 139, in 
> __repr__
> data = list(self[:REPR_OUTPUT_SIZE + 1])
>   File "/Downloads/Django-1.8a1/django/db/models/query.py", line 163, in 
> __iter__
> self._fetch_all()
>   File "/Downloads/Django-1.8a1/django/db/models/query.py", line 955, in 
> _fetch_all
> self._result_cache = list(self.iterator())
>   File "/Downloads/Django-1.8a1/django/db/models/query.py", line 1075, in 
> iterator
> for row in self.query.get_compiler(self.db).results_iter():
>   File "/Downloads/Django-1.8a1/django/db/models/sql/compiler.py", line 
> 780, in results_iter
> results = self.execute_sql(MULTI)
>   File "/Downloads/Django-1.8a1/django/db/models/sql/compiler.py", line 
> 826, in execute_sql
> cursor.execute(sql, params)
>   File "/Downloads/Django-1.8a1/django/db/backends/utils.py", line 80, in 
> execute
> return super(CursorDebugWrapper, self).execute(sql, params)
>   File "/Downloads/Django-1.8a1/django/db/backends/utils.py", line 65, in 
> execute
> return self.cursor.execute(sql, params)
>   File "/Downloads/Django-1.8a1/django/db/utils.py", line 95, in __exit__
> six.reraise(dj_exc_type, dj_exc_value, traceback)
>   File "/Downloads/Django-1.8a1/django/db/backends/utils.py", line 65, in 
> execute
> return self.cursor.execute(sql, params)
> ProgrammingError: aggregate functions are not allowed in GROUP BY
> LINE 1: ... GROUP BY (TO_CHAR(ts, 'D')), ROUND(COALESCE(CAST(Sum("rev")...
>  ^
>
> >>> print qs.query
> SELECT (TO_CHAR(ts, 'D')) AS "dow", SUM("testgroupby_everydaycost"."cost") 
> AS "sum_cost", SUM("testgroupby_everydaycost"."rev") AS "sum_rev", 
> ROUND(COALESCE(CAST(Sum("rev") as numeric) / NULLIF(CAST(Sum("cost") as 
> numeric),0), 0), 2) AS "roi" FROM "testgroupby_everydaycost" GROUP BY 
> (TO_CHAR(ts, 'D')), ROUND(COALESCE(CAST(Sum("rev") as numeric) / 
> NULLIF(CAST(Sum("cost") as numeric),0), 0), 2)
> >>>
>
>
> With earlier version, this worked fine for me.
>
>
> $ python manage.py shell
> Python 2.7.5 (default, Mar  9 2014, 22:15:05)
> [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
> >>>
> >>> from testgroupby.models import *
> >>> from django.db.models import Q, Count, Min, Sum, Func, FloatField
> >>> qs = everydaycost.objects.all()
> >>> qs = qs.extra(select={'dow': "TO_CHAR(ts, 'D')"})
> >>> qs = qs.values('dow')
> >>> qs = qs.annotate(sum_cost=Sum('
> cost'))
> >>> qs = qs.annotate(sum_rev=Sum('rev'))
> >>> qs = qs.annotate(roi=Func(A='CAST(Sum("rev") as numeric)', 
> B='CAST(Sum("cost") as numeric)',
> ... template='ROUND(COALESCE(%(A)s / NULLIF(%(B)s,0), 0), 
> 2)', output_field=FloatField()))
> >>> print qs
> DEBUG(0.002) SELECT (TO_CHAR(ts, 'D')) AS "dow", 
> SUM("testgroupby_everydaycost"."cost") AS "

Re: Django: How to customize the admin form for specific model

2015-01-27 Thread Collin Anderson
Hi,

You could have the images be inline:

class CommentImageInline(models.TabularInline):
model = CommentImage
extra = 0

class CommentAdmin(models.ModelAdmin):
inlines = [CommentImageInline]

Though, you may need to use a custom widget to get the actual images to 
show up.

Collin

On Saturday, January 24, 2015 at 2:31:02 PM UTC-5, Shoaib Ijaz wrote:
>
> First of all I apologize the question title can be unrelated to my query. 
> I am also confused what I want to do because I am less familiar with django.
>
> I want to create simple comment system. The requirement is clear that user 
> can post comment with multiple images.Every comment should have reply. so I 
> created following models.
>
> #comment table class Comments(models.Model):
> parent = models.ForeignKey('self',null=True) // for comment reply
> description = models.TextField(max_length=1000, blank=False, null=False)
>
> class Meta:
> db_table = u'comments'
>
> #images tableclass CommentImages(models.Model):
> comment = models.ForeignKey(Comments)
> image = models.CharField(max_length=250, blank=False, null=False)
>
> class Meta:
> db_table = u'comments_images'
>
> I have query about admin side how can i manage these things?
>
> I want to show images list when admin view the specific comment.
>
> Admin can view replies of specific comment.
>
> Here i draw the example. [image: enter image description here]
>
> So I dont want to ask about coding. I want to know what techniques will be 
> used to change the admin view. I am using admin panel for others models too 
> so I want to change the specific model view.
>
> How can I get these things? Thank you
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c399d663-c514-439d-b7e4-bab765fc6ea4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: unable to open project

2015-01-27 Thread Collin Anderson
Hi,

What happens when you try?

Collin

On Saturday, January 24, 2015 at 3:59:55 AM UTC-5, abhishek kumar wrote:
>
> I am unable to open my project again.  As i am using virtual enviroment in 
> windows.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/304c2a89-001a-4b01-ab2b-3578e327766e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do you link your Django project to a domain

2015-01-27 Thread Collin Anderson
I use namecheap, but yes, domains.google.com has a nice user interface.

On Saturday, January 24, 2015 at 8:22:33 AM UTC-5, patrickbeeson wrote:
>
> You might also check out Google's recently launched domain registrar at 
> domains.google.com.
>
> On Saturday, January 24, 2015 at 2:01:43 AM UTC-5, djangocharm2020 wrote:
>>
>> pretty much have a project built but now want to purchase a domain to 
>> link it live . Do you guys have any suggestions on who i should go with 
>> like godaddy.com.
>>
>> I also need to know is there a special step or code that is needed to add 
>> to the project?
>>
>> Thanks 
>>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d49b77bc-a760-4867-8611-0f80cac9717c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: login_required in urlpatterns TypeError 'tuple' object is not callable

2015-01-27 Thread Collin Anderson
Hi,

Something like this might work:

from home.urls import urlpatterns as home_urls


url('^home/', include(list(login_required(x) for x in home_urls)))

Collin

On Friday, January 23, 2015 at 7:09:30 PM UTC-5, Vijay Khemlani wrote:
>
> I may be mistaken, but I don't think you can decorate an entire "include" 
> call
>
> On Fri, Jan 23, 2015 at 8:51 PM, Neto 
> > wrote:
>
>> Hi, I'm using login_required in url patterns but it does an error:
>>
>> urls.py
>>
>> from django.conf.urls import patterns, include, url
>> from django.contrib.auth.decorators import login_required
>>
>>
>> urlpatterns = patterns('',
>> url(r'^home/', login_required(include('home.urls'))),
>>
>> )
>>
>>
>> error:
>> TypeError at /home/
>>
>> 'tuple' object is not callable
>>
>> how to fix this?
>>
>> -- 
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/a0a93906-ce10-4b46-bb7a-67aa8d458a6c%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ad2714cb-9dfc-4b62-a636-aa7d90419f6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dictionary in admin interface

2015-01-27 Thread Collin Anderson
Hi,

The admin doesn't really have a way to do this. You could edit KeyValuePair 
inline on Dictionary.

Why not have a "Params" model that has a ForeignKey to Request?

Collin

On Friday, January 23, 2015 at 1:32:21 PM UTC-5, Sven Mäurer wrote:
>
> I want to manage a dictionary inline over the admin interface. These are 
> my models. What I got working is of course a separated management of 
> request and dictionary. But I want to add key value pairs in the request 
> admin interface with a TabularInline. Do I have to skip the dictionary in 
> some way or what do I have to do?
>
> class Dictionary(models.Model):
> name = models.CharField(max_length=255)
> class KeyValuePair(models.Model):
> container = models.ForeignKey(Dictionary, db_index=True)
> key = models.CharField(max_length=240, db_index=True)
> value = models.CharField(max_length=240, db_index=True)
> class Request(models.Model):
> params = models.ForeignKey(Dictionary, related_name="params_map", 
> blank=True, null=True)
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/89c71541-3395-4d27-9e5f-f01c5d592744%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to detect (daily) User Login when using cookies?

2015-01-27 Thread Collin Anderson
Hi,

Would it make sense to simply keep a record of when the last time you've 
seen the user is?

Collin

On Friday, January 23, 2015 at 4:43:41 AM UTC-5, Tobias Dacoir wrote:
>
> I'm using django-allauth and I receive a signal when a user logs in. Now I 
> want to store each day the user logs in. However, when the user does not 
> logout he can still log in the next day thanks to the cookies. I know that 
> I can set SESSION_EXPIRE_AT_BROWSER_CLOSE to True in settings.py. But this 
> may annoy some Users. 
>
> So is there a way to use cookies but still tell if a User has accessed the 
> site for the first time today?
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ff24698c-f21d-4a28-a78e-55093d8cf15b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to save object with images while using FormWizard in Django 1.7 and Python 3.4

2015-01-27 Thread Collin Anderson
Hi,

Use items() instead of iteritems().

Collin

On Thursday, January 22, 2015 at 11:31:23 AM UTC-5, Frankline wrote:
>
> ​Hi all​,
> I am having a problem saving a Django form using the *FormWizard 
> * 
> while using *Django 1.7* and *Python 3.4*. Below is my code:
>
> *models.py*
>
> ...class Advert(models.Model):
> ... # Some irelevant code removed for brevity
> owner = models.ForeignKey(settings.AUTH_USER_MODEL, db_index=True, 
> blank=False, null=False)
> title = models.CharField(_("Title"), max_length=120)
> description = models.TextField(_("Description"), default='')
> category = models.ForeignKey(AdCategory, db_index=True, 
> related_name='ad_category', verbose_name=_('Category'))
> status = models.IntegerField(choices=ADVERT_STATES, default=0)
> adtype = models.IntegerField(choices=ADTYPES, default=1)
> price = models.DecimalField(_('Price'), max_digits=12, decimal_places=2, 
> blank=True, default=0,
> help_text=_('Price'), 
> validators=[MinValueValidator(0)])
> ...class AdvertImage(models.Model):
>
> def generate_new_filename(instance, filename):
> IMAGE_UPLOAD_DIR = "advert_images"
> old_fname, extension = os.path.splitext(filename)
> return '%s/%s%s' % (IMAGE_UPLOAD_DIR, uuid.uuid4().hex, extension)
> 
> advert = models.ForeignKey(Advert, related_name='images')
> image = models.ImageField(upload_to=generate_new_filename, null=True, 
> blank=True)
>
>
> *forms.py*
>
> from django.forms.models import inlineformset_factoryfrom django import 
> formsfrom django.forms import ModelForm, RadioSelect, TextInput
> from .models import Advert, AdvertImage
>
> class AdvertCategoryForm(ModelForm):
>
> class Meta:
> model = Advert
> fields = ('category',)
>
> class AdvertDetailsForm(ModelForm):
>
> class Meta:
> model = Advert
> fields = ('title', 'description', 'location', 'adtype', 'price')
>
> class AdvertImageForm(ModelForm):
>
> class Meta:
> model = AdvertImage
> fields = ('image',)
>
> AdvertImageFormset = inlineformset_factory(Advert, AdvertImage, 
> fields=('image',), can_delete=False, extra=3, max_num=3)
>
>
> FORMS = [("ad_category", AdvertCategoryForm),
>  ("ad_details", AdvertDetailsForm),
>  ("ad_images", AdvertImageFormset)]
>
> TEMPLATES = {"ad_category": "adverts/advert_category_step.html",
>  "ad_details": "adverts/advert_details_step.html",
>  "ad_images": "adverts/advert_images_step.html"}
>
>
> *views.py*
>
> ...class AdvertWizard(LoginRequiredMixin, SessionWizardView):
>
> form_list = FORMS
> file_storage = 
> FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT))
>
> def get_template_names(self):
> return [TEMPLATES[self.steps.current]]
>
> ...
>
> def done(self, form_list, **kwargs):
> advert = Advert()
> """for form in form_list:for field, value in 
> form.cleaned_data.iteritems():setattr(advert, field, value)"""
>
> form_dict = {}
> for form in form_list:
> form_dict.update(form.cleaned_data)
>
> advert.owner = self.request.user
> advert.save()
> redirect(advert)
>
>
> ​The problem occurs in the done method while saving the form:
>
> ValueError at /ads/new
>
> dictionary update sequence element #0 has length 3; 2 is required
>
> Request Method:POSTRequest URL:http://localhost:8000/ads/newDjango 
> Version:1.7.1Exception Type:ValueErrorException Value:
>
> dictionary update sequence element #0 has length 3; 2 is required
>
> Exception 
> Location:/home/frank/Projects/python/django/pet_store/src/petstore/apps/adverts/views.py
>  
> in done, line 147Python Executable:
> /home/frank/.virtualenvs/petstore/bin/pythonPython Version:3.4.0
>
>- 
>
> /home/frank/Projects/python/django/pet_store/src/petstore/apps/adverts/views.py
> in done
>1. 
>   
>   form_dict.update(form.cleaned_data)
>   
>   ...
>▶ Local vars 
>
> However, when I replace the following code:
>
> form_dict = {}
> for form in form_list:
> form_dict.update(form.cleaned_data)
>
> with this one
>
> for form in form_list:
> for field, value in form.cleaned_data.iteritems():
> setattr(advert, field, value)
>
> I now get the following error:
>
> AttributeError at /ads/new
>
> 'dict' object has no attribute 'iteritems'
>
> Request Method:POSTRequest URL:http://localhost:8000/ads/newDjango 
> Version:1.7.1Exception Type:AttributeErrorException Value:
>
> 'dict' object has no attribute 'iteritems'
>
> Exception 
> Location:/home/frank/Projects/python/django/pet_store/src/petstore/apps/adverts/views.py
>  
> in done, line 140Python Executable:
> /home/frank/.virtualenvs/petstore/bin/pytho

  1   2   3   4   5   6   7   8   9   10   >