What's the best way to auto convert a model field values before it is rendered?

2016-04-26 Thread jorrit787
Do you need to do actual math with the converted values, or is it just a matter 
of displaying the original value as the converted value in the template to 
those users who prefer seeing Fahrenheit? In the latter case all you would have 
to do is create a custom template tag that takes the original value and 
displays it as Fahrenheit. 

-- 
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/32a473fc-92ba-4941-ab34-a405ee4f9439%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django (stuck at the end of the tutorial)

2016-04-26 Thread Cronos Cto
Could you give me an example or so Vijay Khemali?

-- 
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/b39236d6-b018-48cd-b94a-1857ea1ec32a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django (stuck at the end of the tutorial)

2016-04-26 Thread Vijay Khemlani
You still haven't defined a rule to handle the root path, just admin and
sistema

On Tue, Apr 26, 2016 at 8:56 PM, Cronos Cto  wrote:

>
> 
> ´
>
>
> Doesnt seem to fix it still. I have no clue how to go further, totally new
> to django.
>
>
>
> --
> 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/64ae0a3f-7138-4a4b-8fbb-817192f55207%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3hv%3DtvGEDqDd01krHaC2nhPLfRujjY5U0OcvNNzzqurg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django (stuck at the end of the tutorial)

2016-04-26 Thread Cronos Cto



´


Doesnt seem to fix it still. I have no clue how to go further, totally new 
to django.



-- 
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/64ae0a3f-7138-4a4b-8fbb-817192f55207%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: (Newbie) Stuck with annotate() docs

2016-04-26 Thread Tim Graham
Looks like a typo. Does the rest of the example make sense and work if that 
line is changed to "Book.objects.first().chapters"?

On Tuesday, April 26, 2016 at 12:50:31 PM UTC-4, Ankush Thakur wrote:
>
> Folks, I'm having exceptional trouble understanding annotate(), 
> aggregate(), and their various combinations. I'm currently stuck here: 
> https://docs.djangoproject.com/en/1.9/topics/db/aggregation/#combining-multiple-aggregations
>
> The example here uses Book.objects.first().chapters.count(), but there's 
> no chapters model or field at the start of the tutorial. It's frustrating, 
> to say the least. Even if I set up a separate application to test this 
> myself, what do I make of "chapters"? Is it another model with many-to-many 
> relation with Book? When I ran an example with the following models:
>
> class Author(models.Model):
> name = models.CharField(max_length=100)
> age = models.IntegerField()
>
> class Book(models.Model):
> name = models.CharField(max_length=300)
> chapters = models.IntegerField()
> authors = models.ManyToManyField(Author)
>
> I got: 
>
> >>> Book.objects.first().chapters.count()
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'int' object has no attribute 'count'
> >>> 
>
> So basically, I feel like I'm screwed. 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6527650e-9b58-47a5-8e65-95fd976902cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Test runner wants to run models package?!

2016-04-26 Thread Tim Graham
Could you try Python 3.4.x? I ran into some issues with Django's own test 
suite [0] due to some import changes in Python 3.5 [1].

[0] https://code.djangoproject.com/ticket/23763#comment:11
[1] http://bugs.python.org/issue7559

On Tuesday, April 26, 2016 at 6:04:56 PM UTC-4, Torsten Bronger wrote:
>
> Hallöchen! 
>
> With Django 1.9.5 (rest are original Ubuntu 16.04 packages) and 
> Python 3.5.1, "manage.py test myapp" tries to run the *models* 
> package of myapp as a test module: 
>
> user@localhost:~/src/myproject/myproject$ ./manage.py test myapp 
> --pattern=invalid_pattern 
> Creating test database for alias 'default'... 
> Destroying old test database for alias 'default'... 
> E 
> == 
> ERROR: myproject.myapp.models (unittest.loader._FailedTest) 
> -- 
> ImportError: Failed to import test module: myproject.myapp.models 
> Traceback (most recent call last): 
>   File "/usr/lib/python3.5/unittest/loader.py", line 462, in 
> _find_test_path 
> package = self._get_module_from_name(name) 
>   File "/usr/lib/python3.5/unittest/loader.py", line 369, in 
> _get_module_from_name 
> __import__(name) 
>   File "/home/user/src/myproject/myproject/myapp/models/__init__.py", 
> line 26, in  
> from .physical_processes import * 
>   File 
> "/home/user/src/myproject/myproject/myapp/models/physical_processes.py", 
> line 66, in  
> class Substrate(PhysicalProcess): 
>   File 
> "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 
> 102, in __new__ 
> "INSTALLED_APPS." % (module, name) 
> RuntimeError: Model class 
> myproject.myapp.models.physical_processes.Substrate doesn't declare an 
> explicit app_label and isn't in an application in INSTALLED_APPS. 
>
>
> -- 
> Ran 1 test in 0.000s 
>
> FAILED (errors=1) 
> Destroying test database for alias 'default'... 
>
>
>
> I chose "invalid_pattern" to limit it to the models package. 
> Without "--pattern", all *real* tests are run, too.  Using Python2, 
> everything is fine.  Does anybody have an idea what's going on here? 
>
> Tschö, 
> Torsten. 
>
> -- 
> Torsten BrongerJabber ID: torsten...@jabber.rwth-aachen.de 
>  
>
>

-- 
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/a7b14bea-022c-4f9d-984d-2c63fdf60b8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Test runner wants to run models package?!

2016-04-26 Thread Torsten Bronger
Hallöchen!

With Django 1.9.5 (rest are original Ubuntu 16.04 packages) and
Python 3.5.1, "manage.py test myapp" tries to run the *models*
package of myapp as a test module:

user@localhost:~/src/myproject/myproject$ ./manage.py test myapp 
--pattern=invalid_pattern
Creating test database for alias 'default'...
Destroying old test database for alias 'default'...
E
==
ERROR: myproject.myapp.models (unittest.loader._FailedTest)
--
ImportError: Failed to import test module: myproject.myapp.models
Traceback (most recent call last):
  File "/usr/lib/python3.5/unittest/loader.py", line 462, in _find_test_path
package = self._get_module_from_name(name)
  File "/usr/lib/python3.5/unittest/loader.py", line 369, in 
_get_module_from_name
__import__(name)
  File "/home/user/src/myproject/myproject/myapp/models/__init__.py", line 
26, in 
from .physical_processes import *
  File 
"/home/user/src/myproject/myproject/myapp/models/physical_processes.py", line 
66, in 
class Substrate(PhysicalProcess):
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", 
line 102, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class 
myproject.myapp.models.physical_processes.Substrate doesn't declare an explicit 
app_label and isn't in an application in INSTALLED_APPS.


--
Ran 1 test in 0.000s

FAILED (errors=1)
Destroying test database for alias 'default'...



I chose "invalid_pattern" to limit it to the models package.
Without "--pattern", all *real* tests are run, too.  Using Python2,
everything is fine.  Does anybody have an idea what's going on here?

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de

-- 
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/87wpnkkoxl.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django (stuck at the end of the tutorial)

2016-04-26 Thread Patrick Harding
maybe giving it a namespace would handle it for you? such as 
 include('sistema.urls', namespace='sistema')

if not you can try this. the error i get is that you should "pass the 
callable instead" which means in your imports include the views that you 
want to import, then call them in you url statements.
for example:

from .views import (
post_list,
post_create,
post_detail,
post_update,
post_delete,
)

urlpatterns = [
url(r'^$', post_list, name='list'),
url(r'^create/$', post_create, name='create'),
url(r'^(?P\d+)/$', post_detail, name='detail'),
url(r'^(?P\d+)/edit/$', post_update, name='update'),
url(r'^(?P\d+)/delete/$', post_delete, name='delete'),


]


here you are calling the view, then giving it a name that will show up in 
the URL.

-- 
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/9f969947-ced2-4414-9c6f-8a53cf0022a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Trying to extend the User model to create a user profile page

2016-04-26 Thread Patrick Harding
I am creating an app for our company to have users log in, create a profile 
page, and create updates on some personal progress. I have handled logging 
in and registering with django-registration, and have created the app for 
updates, but i'm not able to create a profile page extending the user's 
information. 

I've tried a few ways to do it (django-custom-user, a few tutorials, 
documentation, etc.) but I can't seem to make it work right. I'm assuming 
it would be a good idea to create an entirely new app for this profile 
page, allowing the user to create on the initial login and edit as changes 
require. I have these capabilities already in the updates section. How can 
I make this work right? 


-- 
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/7394b722-dce2-4c0f-865c-0c3f286781a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What's the best way to auto convert a model field values before it is rendered?

2016-04-26 Thread Vince
I need to store and retrieve temperatures in a model.  I'd like to store 
all the values in celsius.  However some users prefer to view the value in 
fahrenheit.
What is the recommended way to setup a model like this?  

Perhaps manually convert the values in the view and on save?
Or is it possible to use python properties in a model for saves, updates 
and gets? 
Or is some other practice preferred?

class Temp(models.Model):
user = models.ForeignKey(User, unique=False)
temperature = models.FloatField(null=True, blank=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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ee6de0ba-f1b6-4faf-a7eb-9ac47d0f3c38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django apparently can't handle that error.

2016-04-26 Thread Michal Petrucha
On Tue, Apr 26, 2016 at 08:17:40PM +0200, Michal Petrucha wrote:
> Have you considered altering the table for Log to include an ON DELETE
> CASCADE clause instead? That would make the error go away without too
> much effort, even though I still think the behavior you are
> implementing is simply incorrect.

Doh, there might be an even easier solution:

class Account(models.Model):
marked_for_delete = models.BooleanField(default=False)

def delete(self):
with transaction.atomic():
self.marked_for_delete = True
self.save()
super().delete()


class Car(models.Model):
account = models.ForeignKey('Account', on_delete=models.CASCADE)


class Log(models.Model):
account = models.ForeignKey('Account', on_delete=models.CASCADE)


class CarLog(Log):
car = models.ForeignKey('Car', null=True, blank=True, 
on_delete=models.SET_NULL)


@receiver(post_delete, sender=Car):
def create_car_log(sender, instance, **kwargs):
if not instance.account.marked_for_delete:
CarLog.objects.create(
account=instance.account,
)


Maybe, if it is guaranteed that during a delete operation, the same
instance of Account is used even when accessed from related objects,
you might be able to leave out the BooleanField, and just set an
attribute instead, but I'm not sure at the moment, so I'll leave it to
you to figure that part out.

Michal

-- 
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/20160426193051.GU435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: New to Django (stuck at the end of the tutorial)

2016-04-26 Thread Cronos Cto
I have tried the include solution. Just creates more erros as knbk said.

-- 
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/cf19247e-c626-41b7-9be0-98ae7a4f012a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django (stuck at the end of the tutorial)

2016-04-26 Thread Cronos Cto


terça-feira, 26 de Abril de 2016 às 08:33:09 UTC+1, Cronos Cto escreveu:
>
>
> Hello Django Lovers.
>
> So I started on Django as project of mine. Seems like a great first 
> framework to start on. At the moment I am stuck at this:
>
>
>
> 
> This was after what I encountered at the end of the Django oficial post 
> app tutorial.
>
> I tried several ways to solve it. The problem seems to lay in the url.py 
> file, but I can not seem to solve it.
>
>
> 
>
> Thank you to anyone that can help me solve it.
>


I have tried the include, and does not seem to solve problem, just creates 
more errors as knbk said. 

-- 
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/36d60580-d4b9-4e8c-811c-1d64041afadf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django apparently can't handle that error.

2016-04-26 Thread Michal Petrucha
On Tue, Apr 26, 2016 at 10:02:32AM -0700, Neto wrote:
> The right is just Account.objects.last().delete() to delete everything 
> related to account.
> My project has many models related to account, and everything has log, is 
> unfeasible be deleting the rows of each model to the end delete the account.
> Django needs to handle it.

Do you have any concrete suggestion what Django could do better in
this case?

So, to recap, what is happening here is that in the middle of an
attempt to delete object A, you are creating an object B referencing
object A, after a plan has been calculated (and partially executed)
that would otherwise successfully remove object A and everything
referencing it.

Have you considered altering the table for Log to include an ON DELETE
CASCADE clause instead? That would make the error go away without too
much effort, even though I still think the behavior you are
implementing is simply incorrect.

Cheers,

Michal

-- 
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/20160426181740.GT435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: New to Django (stuck at the end of the tutorial)

2016-04-26 Thread knbk
Since 1.9, admin.site.urls is a special case, and you should not use 
include(). If you do, you'll trigger some deprecation warnings due to 
changes to include().
 
On Tuesday, April 26, 2016 at 6:33:40 PM UTC+2, Nikhil Beniwal wrote:
>
> The Problem is in your line 21. 
>
> admin.site.urls should be wrapped inside include like :-
>
> url(r'^admin/', include(admin.site.urls)),
>
> On Tuesday, April 26, 2016 at 1:03:09 PM UTC+5:30, Cronos Cto wrote:
>>
>>
>> Hello Django Lovers.
>>
>> So I started on Django as project of mine. Seems like a great first 
>> framework to start on. At the moment I am stuck at this:
>>
>>
>>
>> 
>> This was after what I encountered at the end of the Django oficial post 
>> app tutorial.
>>
>> I tried several ways to solve it. The problem seems to lay in the url.py 
>> file, but I can not seem to solve it.
>>
>>
>> 
>>
>> Thank you to anyone that can help me solve 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/88fb3e35-1bd0-4070-ab02-1683263273a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django apparently can't handle that error.

2016-04-26 Thread Neto
The right is just Account.objects.last().delete() to delete everything 
related to account.
My project has many models related to account, and everything has log, is 
unfeasible be deleting the rows of each model to the end delete the account.
Django needs to handle it.

Em terça-feira, 26 de abril de 2016 00:58:31 UTC-3, Stephen Butler escreveu:
>
> Damn. It did work once, but now I can't reproduce it. But turning on SQL 
> logging it's clear that what's happening isn't what I said it was.
>
> I get a sequence essentially like this at acct.delete():
>
> -- Django selecting all the things it needs to cascade/update b/c of m2m
>
> SELECT * FROM "myapp_car" WHERE "myapp_car"."account_id" IN (1);
>
> SELECT * FROM "myapp_carlog" INNER JOIN "myapp_log" ON 
> ("myapp_carlog"."log_ptr_id" = "myapp_log"."id") WHERE 
> "myapp_carlog"."car_id" IN (1);
>
> SELECT * FROM "myapp_log" WHERE "myapp_log"."account_id" IN (1);
>
>
> -- Django doing the m2m DELETEs and UPDATEs
>
> DELETE FROM "myapp_carlog" WHERE "myapp_carlog"."log_ptr_id" IN (1);
>
> UPDATE "myapp_carlog" SET "car_id" = NULL WHERE 
> "myapp_carlog"."log_ptr_id" IN (1);
>
> DELETE FROM "myapp_car" WHERE "myapp_car"."id" IN (1);
>
>
> -- This is the signal firing for Car delete
>
> SAVEPOINT "s140735184359424_x3";
>
> SELECT "myapp_account"."id" FROM "myapp_account" WHERE 
> "myapp_account"."id" = 1;
>
> INSERT INTO "myapp_log" ("account_id") VALUES (1) RETURNING 
> "myapp_log"."id";
>
> INSERT INTO "myapp_carlog" ("log_ptr_id", "car_id") VALUES (4, NULL);
>
> RELEASE SAVEPOINT "s140735184359424_x3";
>
>
> -- Outside the signal, more cascades
>
> DELETE FROM "myapp_log" WHERE "myapp_log"."id" IN (1);
>
> -- Finally, delete the account, where we blow up
>
> DELETE FROM "myapp_account" WHERE "myapp_account"."id" IN (1);
>
> So as you can see, the reason the signal Exception isn't caught is because 
> it isn't thrown! The problem is that Django builds a list of every 
> DELETE/UPDATE it needs to make on CarLog and you modify CarLog afterwards.
>
> One way to break this race condition is to call 
> Car.objects.filter(account=acct).delete() first, then acct.delete(). I 
> think that should work, even if it is a little more verbose. Probably will 
> want to wrap that in a transaction.atomic().
>
>
> On Mon, Apr 25, 2016 at 12:46 PM, Neto  > wrote:
>
>> This works for you? Not for me! This error continues to ignore the 
>> exception.
>> Even using exception continues to show django.db.utils.IntegrityError
>>
>> Em domingo, 24 de abril de 2016 00:52:46 UTC-3, Stephen Butler escreveu:
>>>
>>> Ahh, Postgres is the problem. When your exception is thrown then 
>>> Postgres aborts the rest of the transaction. That's how its transaction 
>>> handling works. Even though you ignore the exception in the myapp code, it 
>>> will still cause the transaction to abort when Django tries to call 
>>> commit(). When I was testing I was using sqlite, which behaves differently.
>>>
>>> See the note here: 
>>> https://docs.djangoproject.com/en/1.9/topics/db/transactions/#handling-exceptions-within-postgresql-transactions
>>>
>>> This works for me:
>>>
>>> @receiver(post_delete, sender=Car)
>>> def create_car_log(sender, instance, **kwargs):
>>> sid = transaction.savepoint()
>>> try:
>>> CarLog.objects.create(
>>> account=instance.account,
>>> )
>>> transaction.savepoint_commit(sid)
>>> except:
>>> transaction.savepoint_rollback(sid)
>>>
>>> What I don't get is that using a "with transaction.atomic()" inside the 
>>> try block should do the same thing. But it's not. Maybe someone else knows?
>>>
>>> On Sat, Apr 23, 2016 at 10:19 PM, Neto  wrote:
>>>
 Stephen, I am using Django 1.9.5, PostgreSQL 9.3
 I do not know, maybe the order of the apps may be interfering in the 
 way Django sorts the commands to be sent to the postgresql.

 INSTALLED_APPS = [
 'core',  # here: Account, Log
 'myapp',  # here: Car, CarLog


 What is happening is that post_delete is trying to create a log for an 
 account that does not exist. The exception doesn't works.
 This seems to be a bug.

 Em sábado, 23 de abril de 2016 18:28:08 UTC-3, Stephen Butler escreveu:
>
> Sorry, I did miss that.
>
> I created a quick test project in 1.9 and ran your sample. It works 
> fine for me. The delete() returns that it deleted 4 objects: the Account, 
> Car, Log, and CarLog. There's something else in your project that is 
> causing the error.
>
> On Sat, Apr 23, 2016 at 3:42 PM, Neto  wrote:
>
>> Stephen, CarLog is inheriting Log.
>>
>>
>> Em sábado, 23 de abril de 2016 17:14:57 UTC-3, Stephen Butler 
>> escreveu:
>>>
>>> Look a little closer at the error message:
>>>
>>> Error:

 insert or update on table "myapp_log" violates foreign key 

(Newbie) Stuck with annotate() docs

2016-04-26 Thread Ankush Thakur
Folks, I'm having exceptional trouble understanding annotate(), 
aggregate(), and their various combinations. I'm currently stuck 
here: 
https://docs.djangoproject.com/en/1.9/topics/db/aggregation/#combining-multiple-aggregations

The example here uses Book.objects.first().chapters.count(), but there's no 
chapters model or field at the start of the tutorial. It's frustrating, to 
say the least. Even if I set up a separate application to test this myself, 
what do I make of "chapters"? Is it another model with many-to-many 
relation with Book? When I ran an example with the following models:

class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()

class Book(models.Model):
name = models.CharField(max_length=300)
chapters = models.IntegerField()
authors = models.ManyToManyField(Author)

I got: 

>>> Book.objects.first().chapters.count()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'int' object has no attribute 'count'
>>> 

So basically, I feel like I'm screwed. 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ea169a1e-d55a-457c-b0bd-19d6d96626d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django (stuck at the end of the tutorial)

2016-04-26 Thread Nikhil Beniwal
The Problem is in your line 21. 

admin.site.urls should be wrapped inside include like :-

url(r'^admin/', include(admin.site.urls)),

On Tuesday, April 26, 2016 at 1:03:09 PM UTC+5:30, Cronos Cto wrote:
>
>
> Hello Django Lovers.
>
> So I started on Django as project of mine. Seems like a great first 
> framework to start on. At the moment I am stuck at this:
>
>
>
> 
> This was after what I encountered at the end of the Django oficial post 
> app tutorial.
>
> I tried several ways to solve it. The problem seems to lay in the url.py 
> file, but I can not seem to solve it.
>
>
> 
>
> Thank you to anyone that can help me solve 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c289c174-4188-45ca-9747-dcaa5125c7fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to retrieve data from deep nested object?

2016-04-26 Thread Said Akhmedbayev
Sorry guys this worked for me

{% for question in subsection.question_set.all %}
{{ question.question_text }}
{% endfor %}

My problem was that I did not realize that Django is smart enough for not 
to show default text in the Question body that I placed in the question 
model. When I inserted a custom text (typed in), everything showed up.

Thanks

On Tuesday, April 26, 2016 at 7:49:39 PM UTC+6, Vijay Khemlani wrote:
>
> I guess it is 
>
> {% for question in subsection.question_set.all %}
>
> based on your models
>
> On Tue, Apr 26, 2016 at 9:33 AM, Said Akhmedbayev  > wrote:
>
>> I am trying to figure out how to loop over deep nested object in Django 
>> template. 
>>
>> Here is my app's code
>>
>> models.py
>>
>> from django.db import models
>>
>>
>> class Unit(models.Model):
>> unit_number = models.PositiveIntegerField(blank=True, null=True, 
>> default=1)
>> title = models.CharField(max_length=150, blank=True, null=True)
>> scripture_ref = models.CharField(max_length=250, blank=True, 
>> null=True)
>>
>> def __str__(self):
>> return self.title
>>
>>
>> class Subsection(models.Model):
>> title = models.CharField(max_length=150, blank=True, null=True)
>> subsection_text = models.TextField(default='SUBSECTION TEXT')
>> unit = models.ForeignKey(Unit, on_delete=models.CASCADE)
>>
>>
>> class Question(models.Model):
>> question_text = models.CharField(max_length=2000, default='QUESTION 
>> TEXT')
>> subsection = models.ForeignKey(Subsection, on_delete=models.CASCADE)
>>
>> views.py
>>
>> from django.shortcuts import get_object_or_404
>> from django.shortcuts import render
>>
>> from .models import Unit
>>
>>
>> def unitdetail(request, unit_id):
>> unit = get_object_or_404(Unit, pk=unit_id)
>> return render(request, 'correspondence_course/unit_detail.html', 
>> {'unit': unit,})
>>
>> unit_detail.html (template)
>>
>> Урок {{ unit.unit_number }}
>> {{ unit.title }}
>>
>>
>> {% for subsection in unit.subsection_set.all %}
>> {{ subsection.title }}
>> {{ subsection.subsection_text }}
>> {% for question in subsection. %} # this is just for reference. It 
>> does not work
>> {{ question.question_text }}
>> {% endfor %}
>> {% endfor %}
>>
>> As you can see I have three class models: Unit, Subsection with back 
>> relationship with Unit and then Question with back relationship with 
>> Subsection.
>>
>> I managed to show in the template (see above) unit.title alone with 
>> subsection.title 
>> and subsection.subsection_text. It is all nice, but I cannot figure out 
>> how to loop over and display questions that are nested to Subsection(s).
>>
>> Can you please help me to figure out how make it 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...@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/2f0d18f4-57c1-4852-b510-114a9b7fffc6%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3b4725e2-d4c7-40c7-af4a-8015b921adf5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to retrieve data from deep nested object?

2016-04-26 Thread Said Akhmedbayev
This does not work for me either :-(

On Tuesday, April 26, 2016 at 7:49:41 PM UTC+6, Dan Tagg wrote:
>
> Does {% for question in subsection.subsection_set.all %} work?
>
> Dan
>
> On 26 April 2016 at 13:33, Said Akhmedbayev  > wrote:
>
>> I am trying to figure out how to loop over deep nested object in Django 
>> template. 
>>
>> Here is my app's code
>>
>> models.py
>>
>> from django.db import models
>>
>>
>> class Unit(models.Model):
>> unit_number = models.PositiveIntegerField(blank=True, null=True, 
>> default=1)
>> title = models.CharField(max_length=150, blank=True, null=True)
>> scripture_ref = models.CharField(max_length=250, blank=True, 
>> null=True)
>>
>> def __str__(self):
>> return self.title
>>
>>
>> class Subsection(models.Model):
>> title = models.CharField(max_length=150, blank=True, null=True)
>> subsection_text = models.TextField(default='SUBSECTION TEXT')
>> unit = models.ForeignKey(Unit, on_delete=models.CASCADE)
>>
>>
>> class Question(models.Model):
>> question_text = models.CharField(max_length=2000, default='QUESTION 
>> TEXT')
>> subsection = models.ForeignKey(Subsection, on_delete=models.CASCADE)
>>
>> views.py
>>
>> from django.shortcuts import get_object_or_404
>> from django.shortcuts import render
>>
>> from .models import Unit
>>
>>
>> def unitdetail(request, unit_id):
>> unit = get_object_or_404(Unit, pk=unit_id)
>> return render(request, 'correspondence_course/unit_detail.html', 
>> {'unit': unit,})
>>
>> unit_detail.html (template)
>>
>> Урок {{ unit.unit_number }}
>> {{ unit.title }}
>>
>>
>> {% for subsection in unit.subsection_set.all %}
>> {{ subsection.title }}
>> {{ subsection.subsection_text }}
>> {% for question in subsection. %} # this is just for reference. It 
>> does not work
>> {{ question.question_text }}
>> {% endfor %}
>> {% endfor %}
>>
>> As you can see I have three class models: Unit, Subsection with back 
>> relationship with Unit and then Question with back relationship with 
>> Subsection.
>>
>> I managed to show in the template (see above) unit.title alone with 
>> subsection.title 
>> and subsection.subsection_text. It is all nice, but I cannot figure out 
>> how to loop over and display questions that are nested to Subsection(s).
>>
>> Can you please help me to figure out how make it 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...@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/2f0d18f4-57c1-4852-b510-114a9b7fffc6%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Wildman and Herring Limited, Registered Office: Sir Robert Peel House, 178 
> Bishopsgate, London, United Kingdom, EC2M 4NJ, Company no: 05766374
>

-- 
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/b8d2cd8a-a75e-4e3e-a964-fc6d9dd60245%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to retrieve data from deep nested object?

2016-04-26 Thread Said Akhmedbayev
Unfortunately, it does not work for me :-(

On Tuesday, April 26, 2016 at 7:49:39 PM UTC+6, Vijay Khemlani wrote:
>
> I guess it is 
>
> {% for question in subsection.question_set.all %}
>
> based on your models
>
> On Tue, Apr 26, 2016 at 9:33 AM, Said Akhmedbayev  > wrote:
>
>> I am trying to figure out how to loop over deep nested object in Django 
>> template. 
>>
>> Here is my app's code
>>
>> models.py
>>
>> from django.db import models
>>
>>
>> class Unit(models.Model):
>> unit_number = models.PositiveIntegerField(blank=True, null=True, 
>> default=1)
>> title = models.CharField(max_length=150, blank=True, null=True)
>> scripture_ref = models.CharField(max_length=250, blank=True, 
>> null=True)
>>
>> def __str__(self):
>> return self.title
>>
>>
>> class Subsection(models.Model):
>> title = models.CharField(max_length=150, blank=True, null=True)
>> subsection_text = models.TextField(default='SUBSECTION TEXT')
>> unit = models.ForeignKey(Unit, on_delete=models.CASCADE)
>>
>>
>> class Question(models.Model):
>> question_text = models.CharField(max_length=2000, default='QUESTION 
>> TEXT')
>> subsection = models.ForeignKey(Subsection, on_delete=models.CASCADE)
>>
>> views.py
>>
>> from django.shortcuts import get_object_or_404
>> from django.shortcuts import render
>>
>> from .models import Unit
>>
>>
>> def unitdetail(request, unit_id):
>> unit = get_object_or_404(Unit, pk=unit_id)
>> return render(request, 'correspondence_course/unit_detail.html', 
>> {'unit': unit,})
>>
>> unit_detail.html (template)
>>
>> Урок {{ unit.unit_number }}
>> {{ unit.title }}
>>
>>
>> {% for subsection in unit.subsection_set.all %}
>> {{ subsection.title }}
>> {{ subsection.subsection_text }}
>> {% for question in subsection. %} # this is just for reference. It 
>> does not work
>> {{ question.question_text }}
>> {% endfor %}
>> {% endfor %}
>>
>> As you can see I have three class models: Unit, Subsection with back 
>> relationship with Unit and then Question with back relationship with 
>> Subsection.
>>
>> I managed to show in the template (see above) unit.title alone with 
>> subsection.title 
>> and subsection.subsection_text. It is all nice, but I cannot figure out 
>> how to loop over and display questions that are nested to Subsection(s).
>>
>> Can you please help me to figure out how make it 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...@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/2f0d18f4-57c1-4852-b510-114a9b7fffc6%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2b33b70d-8246-4717-90b9-69f35d48e117%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to retrieve data from deep nested object?

2016-04-26 Thread Dan Tagg
Does {% for question in subsection.subsection_set.all %} work?

Dan

On 26 April 2016 at 13:33, Said Akhmedbayev  wrote:

> I am trying to figure out how to loop over deep nested object in Django
> template.
>
> Here is my app's code
>
> models.py
>
> from django.db import models
>
>
> class Unit(models.Model):
> unit_number = models.PositiveIntegerField(blank=True, null=True,
> default=1)
> title = models.CharField(max_length=150, blank=True, null=True)
> scripture_ref = models.CharField(max_length=250, blank=True, null=True)
>
> def __str__(self):
> return self.title
>
>
> class Subsection(models.Model):
> title = models.CharField(max_length=150, blank=True, null=True)
> subsection_text = models.TextField(default='SUBSECTION TEXT')
> unit = models.ForeignKey(Unit, on_delete=models.CASCADE)
>
>
> class Question(models.Model):
> question_text = models.CharField(max_length=2000, default='QUESTION
> TEXT')
> subsection = models.ForeignKey(Subsection, on_delete=models.CASCADE)
>
> views.py
>
> from django.shortcuts import get_object_or_404
> from django.shortcuts import render
>
> from .models import Unit
>
>
> def unitdetail(request, unit_id):
> unit = get_object_or_404(Unit, pk=unit_id)
> return render(request, 'correspondence_course/unit_detail.html',
> {'unit': unit,})
>
> unit_detail.html (template)
>
> Урок {{ unit.unit_number }}
> {{ unit.title }}
>
>
> {% for subsection in unit.subsection_set.all %}
> {{ subsection.title }}
> {{ subsection.subsection_text }}
> {% for question in subsection. %} # this is just for reference. It
> does not work
> {{ question.question_text }}
> {% endfor %}
> {% endfor %}
>
> As you can see I have three class models: Unit, Subsection with back
> relationship with Unit and then Question with back relationship with
> Subsection.
>
> I managed to show in the template (see above) unit.title alone with 
> subsection.title
> and subsection.subsection_text. It is all nice, but I cannot figure out
> how to loop over and display questions that are nested to Subsection(s).
>
> Can you please help me to figure out how make it 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2f0d18f4-57c1-4852-b510-114a9b7fffc6%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Wildman and Herring Limited, Registered Office: Sir Robert Peel House, 178
Bishopsgate, London, United Kingdom, EC2M 4NJ, Company no: 05766374

-- 
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/CAPZHCY4w%2Bdz2ied_%2BYX%3D9y_4x3E%3Dn7SF3Z_WLwRBJRJo5uFO3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to retrieve data from deep nested object?

2016-04-26 Thread Vijay Khemlani
I guess it is

{% for question in subsection.question_set.all %}

based on your models

On Tue, Apr 26, 2016 at 9:33 AM, Said Akhmedbayev 
wrote:

> I am trying to figure out how to loop over deep nested object in Django
> template.
>
> Here is my app's code
>
> models.py
>
> from django.db import models
>
>
> class Unit(models.Model):
> unit_number = models.PositiveIntegerField(blank=True, null=True,
> default=1)
> title = models.CharField(max_length=150, blank=True, null=True)
> scripture_ref = models.CharField(max_length=250, blank=True, null=True)
>
> def __str__(self):
> return self.title
>
>
> class Subsection(models.Model):
> title = models.CharField(max_length=150, blank=True, null=True)
> subsection_text = models.TextField(default='SUBSECTION TEXT')
> unit = models.ForeignKey(Unit, on_delete=models.CASCADE)
>
>
> class Question(models.Model):
> question_text = models.CharField(max_length=2000, default='QUESTION
> TEXT')
> subsection = models.ForeignKey(Subsection, on_delete=models.CASCADE)
>
> views.py
>
> from django.shortcuts import get_object_or_404
> from django.shortcuts import render
>
> from .models import Unit
>
>
> def unitdetail(request, unit_id):
> unit = get_object_or_404(Unit, pk=unit_id)
> return render(request, 'correspondence_course/unit_detail.html',
> {'unit': unit,})
>
> unit_detail.html (template)
>
> Урок {{ unit.unit_number }}
> {{ unit.title }}
>
>
> {% for subsection in unit.subsection_set.all %}
> {{ subsection.title }}
> {{ subsection.subsection_text }}
> {% for question in subsection. %} # this is just for reference. It
> does not work
> {{ question.question_text }}
> {% endfor %}
> {% endfor %}
>
> As you can see I have three class models: Unit, Subsection with back
> relationship with Unit and then Question with back relationship with
> Subsection.
>
> I managed to show in the template (see above) unit.title alone with 
> subsection.title
> and subsection.subsection_text. It is all nice, but I cannot figure out
> how to loop over and display questions that are nested to Subsection(s).
>
> Can you please help me to figure out how make it 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2f0d18f4-57c1-4852-b510-114a9b7fffc6%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei3mis6YEx6KCH_B3bVdYU2%2BKGGA8cR1cWP3PL-U7tpTkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using django login functionality in a non django app

2016-04-26 Thread Gergely Polonkai
That means you have to be able to do it via the API. The other solution is
to pop up a web view for these tasks. However, we are moving out from
Django field here, as this is getting more and more a falcon/UX-related
question.



Gergely Polonkai
[image: https://]about.me/gergely.polonkai


2016-04-26 14:19 GMT+02:00 Larry Martell :

> I need to support create user, change password, delete user and forgot
> password.
>
> On Tue, Apr 26, 2016 at 7:32 AM, Gergely Polonkai 
> wrote:
> >
> >
> > That’s not a big issue if you really communicate with Django via a
> web-based API. If the user can’t log in, you can simply redirect them to a
> web page. I don’t see the need for user admin functions, though.
> >
> >
> > Gergely Polonkai
> > about.me/gergely.polonkai
> >
> > 2016-04-26 13:10 GMT+02:00 Larry Martell :
> >>
> >> Well, the issue with simply implementing auth, is that we'd need to
> >> not only implement login, which is easy, but also forgot password, and
> >> all the user admin functions. Since we have that already with django I
> >> want to leverage that and not reinvent the wheel.
> >>
> >> On Tue, Apr 26, 2016 at 2:29 AM, Gergely Polonkai 
> wrote:
> >> > Now I somewhat understand what falcon is, I suggest that you simply
> >> > implement auth on you web app (it seems to me there is none or little
> right
> >> > now. Of course, you don't have to protect all iour views, or you may
> want to
> >> > display a different dataset, but that's another topic.
> >> >
> >> > When that is done, you have to do two things in your Qt app. First,
> make
> >> > sure that when the server says that you are not authorized, pop up a
> login
> >> > window. After a successful login, store the user's credentials for
> later
> >> > use. What type of authentication to use and what to store is up to
> your
> >> > decision: HTTP Basic (store user/password), HTTP session (store the
> session
> >> > cookie) or token (store the token) based auths are the most common
> examples.
> >> >
> >> > Best,
> >> > Gergely
> >> >
> >> > On Apr 26, 2016 00:09, "Larry Martell" 
> wrote:
> >> >>
> >> >> The Qt app talks to the server with web requests routed to python
> code
> >> >> by falcon. It currently has no authentication/authorization of any
> >> >> kind. It's not a web app, you can't just navigate to any page, you
> can
> >> >> only get to parts of the app the code lets you get to.
> >> >>
> >> >> The way I envision it (if possible) is that I would have a decorator
> >> >> just like @login_required, and if that is called and the user is not
> >> >> logged in, it would invoke the django login page - just like it works
> >> >> in django. I think I can do most of this, the part I am unclear on is
> >> >> how I get control from the django login page back to the Qt app.
> >> >>
> >> >> On Mon, Apr 25, 2016 at 5:26 PM, Gergely Polonkai <
> gerg...@polonkai.eu>
> >> >> wrote:
> >> >> > Hello,
> >> >> >
> >> >> > this all depends on how this Qt app communicates with the other end
> >> >> > (server
> >> >> > side). Does it offer *any* kind of authentication/authorization?
> If so,
> >> >> > look
> >> >> > for ways to integrate it with Django. If not, you are screwed
> anyway
> >> >> > (from
> >> >> > security point of view), because even if your app pops up a login
> >> >> > screen,
> >> >> > there can (and will) be ways to get around it.
> >> >> >
> >> >> > Best,
> >> >> > Gergely
> >> >> >
> >> >> > On Apr 25, 2016 22:37, "Larry Martell" 
> wrote:
> >> >> >>
> >> >> >> We have an existing django app with login, change password, and
> forgot
> >> >> >> password functionality.
> >> >> >>
> >> >> >> Then we have this other app built with the falcon framework. The
> >> >> >> client side of that is C++/Qt. That app has no login
> functionality -
> >> >> >> you bring it up and you're in. We would like to somehow use the
> login
> >> >> >> functionality of the django app in the falcon app. Is that even
> >> >> >> possible? I was thinking that in the Qt app I could bring up the
> >> >> >> django login page by invoking the URL for that app. But once they
> log
> >> >> >> in, how could I get control back to the Qt app and not have it
> proceed
> >> >> >> to the django app?
> >> >> >>
> >> >> >> Does this even make any sense? Has anyone ever done anything like
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> 

Re: New to Django (stuck at the end of the tutorial)

2016-04-26 Thread Cristiano Valente
You have defined no view to handle the root url. You only have two routes: 
^/sistema and ^/admin.
Besides, you should wrap admin.site.url in an include().

Il giorno martedì 26 aprile 2016 09:33:09 UTC+2, Cronos Cto ha scritto:
>
>
> Hello Django Lovers.
>
> So I started on Django as project of mine. Seems like a great first 
> framework to start on. At the moment I am stuck at this:
>
>
>
> 
> This was after what I encountered at the end of the Django oficial post 
> app tutorial.
>
> I tried several ways to solve it. The problem seems to lay in the url.py 
> file, but I can not seem to solve it.
>
>
> 
>
> Thank you to anyone that can help me solve 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/488bd059-66a7-4151-accf-7c34a707cf55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with defining Models for ManyToMany and OneToMany relationships...

2016-04-26 Thread Bruce Whealton
Having followed all the suggestions, I am now stuck.  I have simplified the 
database by removing one model.  I get to the point of 
python manage.py makemigrations and it returns with what looks right. 
 However, the migrate command just throws out a bunch of errors.  For some 
reason,
it is looking at the choices variable field and telling me that 'following' 
is not an integer field.  From the directions I read, in similar posts, it 
seemed like too many parentheses were used for the 
CHOICES.  

Here is what I have now.  I hope this is helpful in getting this to work.
See below:

from django.db import models


class ContactOrOrganization(models.Model):
name = models.CharField(max_length=40)
organization = models.CharField(max_length=60, null=True, blank=True)
street_line1 = models.CharField("Street Line 1", max_length=50, 
null=True, blank=True)
street_line2 = models.CharField("Street Line 2", max_length=50, 
null=True, blank=True)
city = models.CharField(max_length=40, null=True, blank=True)
state = models.CharField(max_length=40, null=True, blank=True)
zipcode = models.CharField(max_length=20, blank=True, null=True)
phone1 = models.CharField(max_length=20, null=True, blank=True)
phone2 = models.CharField(max_length=20, null=True, blank=True)
email = models.EmailField(max_length=60, null=True, blank=True)
website = models.URLField(max_length=90, null=True, blank=True)
connections = models.ForeignKey('Connection', on_delete=models.CASCADE)


class Connection(models.Model):
CHOICES = (('following', 'Following'),
('family', 'Family'),
('friend', 'Friend'),
('clients', 'Clients'),
('recruiters', 'Recruiters'),
('acquaintances', 'Acquaintances'),
('employers', 'Employers'),
('Employment_Agencies', 'Employment Agencies'),
('unspecified', 'Unspecified'),
)
organization = models.ForeignKey("ContactOrOrganization", 
related_name="Contact_Organization", null=True, blank=True)
contact = models.ForeignKey("ContactOrOrganization", 
related_name="contact", null=True, blank=True)
connection_type = models.CharField(max_length=60, choices=CHOICES)

Thanks in advance for any help,
Bruce

-- 
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/eb67f110-3c66-4098-ad80-c5a7cbc85822%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to retrieve data from deep nested object?

2016-04-26 Thread Said Akhmedbayev
I am trying to figure out how to loop over deep nested object in Django 
template. 

Here is my app's code

models.py

from django.db import models


class Unit(models.Model):
unit_number = models.PositiveIntegerField(blank=True, null=True, 
default=1)
title = models.CharField(max_length=150, blank=True, null=True)
scripture_ref = models.CharField(max_length=250, blank=True, null=True)

def __str__(self):
return self.title


class Subsection(models.Model):
title = models.CharField(max_length=150, blank=True, null=True)
subsection_text = models.TextField(default='SUBSECTION TEXT')
unit = models.ForeignKey(Unit, on_delete=models.CASCADE)


class Question(models.Model):
question_text = models.CharField(max_length=2000, default='QUESTION 
TEXT')
subsection = models.ForeignKey(Subsection, on_delete=models.CASCADE)

views.py

from django.shortcuts import get_object_or_404
from django.shortcuts import render

from .models import Unit


def unitdetail(request, unit_id):
unit = get_object_or_404(Unit, pk=unit_id)
return render(request, 'correspondence_course/unit_detail.html', 
{'unit': unit,})

unit_detail.html (template)

Урок {{ unit.unit_number }}
{{ unit.title }}


{% for subsection in unit.subsection_set.all %}
{{ subsection.title }}
{{ subsection.subsection_text }}
{% for question in subsection. %} # this is just for reference. It does 
not work
{{ question.question_text }}
{% endfor %}
{% endfor %}

As you can see I have three class models: Unit, Subsection with back 
relationship with Unit and then Question with back relationship with 
Subsection.

I managed to show in the template (see above) unit.title alone with 
subsection.title 
and subsection.subsection_text. It is all nice, but I cannot figure out how 
to loop over and display questions that are nested to Subsection(s).

Can you please help me to figure out how make it 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f0d18f4-57c1-4852-b510-114a9b7fffc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using django login functionality in a non django app

2016-04-26 Thread Larry Martell
I need to support create user, change password, delete user and forgot password.

On Tue, Apr 26, 2016 at 7:32 AM, Gergely Polonkai  wrote:
>
>
> That’s not a big issue if you really communicate with Django via a web-based 
> API. If the user can’t log in, you can simply redirect them to a web page. I 
> don’t see the need for user admin functions, though.
>
>
> Gergely Polonkai
> about.me/gergely.polonkai
>
> 2016-04-26 13:10 GMT+02:00 Larry Martell :
>>
>> Well, the issue with simply implementing auth, is that we'd need to
>> not only implement login, which is easy, but also forgot password, and
>> all the user admin functions. Since we have that already with django I
>> want to leverage that and not reinvent the wheel.
>>
>> On Tue, Apr 26, 2016 at 2:29 AM, Gergely Polonkai  
>> wrote:
>> > Now I somewhat understand what falcon is, I suggest that you simply
>> > implement auth on you web app (it seems to me there is none or little right
>> > now. Of course, you don't have to protect all iour views, or you may want 
>> > to
>> > display a different dataset, but that's another topic.
>> >
>> > When that is done, you have to do two things in your Qt app. First, make
>> > sure that when the server says that you are not authorized, pop up a login
>> > window. After a successful login, store the user's credentials for later
>> > use. What type of authentication to use and what to store is up to your
>> > decision: HTTP Basic (store user/password), HTTP session (store the session
>> > cookie) or token (store the token) based auths are the most common 
>> > examples.
>> >
>> > Best,
>> > Gergely
>> >
>> > On Apr 26, 2016 00:09, "Larry Martell"  wrote:
>> >>
>> >> The Qt app talks to the server with web requests routed to python code
>> >> by falcon. It currently has no authentication/authorization of any
>> >> kind. It's not a web app, you can't just navigate to any page, you can
>> >> only get to parts of the app the code lets you get to.
>> >>
>> >> The way I envision it (if possible) is that I would have a decorator
>> >> just like @login_required, and if that is called and the user is not
>> >> logged in, it would invoke the django login page - just like it works
>> >> in django. I think I can do most of this, the part I am unclear on is
>> >> how I get control from the django login page back to the Qt app.
>> >>
>> >> On Mon, Apr 25, 2016 at 5:26 PM, Gergely Polonkai 
>> >> wrote:
>> >> > Hello,
>> >> >
>> >> > this all depends on how this Qt app communicates with the other end
>> >> > (server
>> >> > side). Does it offer *any* kind of authentication/authorization? If so,
>> >> > look
>> >> > for ways to integrate it with Django. If not, you are screwed anyway
>> >> > (from
>> >> > security point of view), because even if your app pops up a login
>> >> > screen,
>> >> > there can (and will) be ways to get around it.
>> >> >
>> >> > Best,
>> >> > Gergely
>> >> >
>> >> > On Apr 25, 2016 22:37, "Larry Martell"  wrote:
>> >> >>
>> >> >> We have an existing django app with login, change password, and forgot
>> >> >> password functionality.
>> >> >>
>> >> >> Then we have this other app built with the falcon framework. The
>> >> >> client side of that is C++/Qt. That app has no login functionality -
>> >> >> you bring it up and you're in. We would like to somehow use the login
>> >> >> functionality of the django app in the falcon app. Is that even
>> >> >> possible? I was thinking that in the Qt app I could bring up the
>> >> >> django login page by invoking the URL for that app. But once they log
>> >> >> in, how could I get control back to the Qt app and not have it proceed
>> >> >> to the django app?
>> >> >>
>> >> >> Does this even make any sense? Has anyone ever done anything like 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY6B3hGoORFf588r_bFUo%3D8phOa-pXy6TcP%3DGxM4X0N_qg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with defining Models for ManyToMany and OneToMany relationships...

2016-04-26 Thread Bruce Whealton
Mike,
 So, I tried your idea for reorganizing the models, and just 
removed Organization and instead setup
ContactOrOrganization as a class.  
It seemed to work ok, in terms of migrating fine.  However, the database 
now lacks a ContactsOrOrganization 
table.  
Oops, my mistake, it does have a table now for that model.  I wonder if I 
need a ForeignKey field in the ContactsOrOrganization table?
Bruce


Anyway, I will try to remove the ManyToMany statement from the Connections 
Model.  
I would then have one Contact or Organization maps to many Connection 
types.  

On Sunday, April 24, 2016 at 1:13:16 AM UTC-4, Mike Dewhirst wrote:
>
>
> I think you should rethink your Contact and Organization classes and see 
> if you can eliminate one or the other. A single table for both would 
> simplify the problem because the Connection class can implement as many 
> connections as you like. 
>
> For example ... 
>
> class ContactOrOrganization(etc): 
>  various detail fields ... 
>
> class Connection(etc): 
>  organization = ForeignKey("ContactOrOrganization", 
>  related_name="organization") 
>  contact = ForeignKey("ContactOrOrganization", 
>  related_name="contact") 
>
> Just because I used related_name that way means nothing. You can connect 
> contacts together or organizations together. Also, you can add other 
> fields to Connection with which to describe the relationship. 
>
> Mike 
>
> > I wanted to use the Organization as a foreign key on the Contact model. 
> > Â I could have more than one contact from 
> > an Organization. Â The Connection model is inspired by the Google Plus 
> > idea of "Circles" - e.g. friends, 
> > family, following, etc. Â  So, this would be a many-to-many 
> relationship. Â 
> > 
> > My problems are (1) I cannot create connections without specifying a 
> > contact. Â 
> > (2) If I was adding a contact using the admin interface, how do I allow 
> > no value for that foreign field 
> > or allow for some kind of ajax type of text completion? Â If a person is 
> > family or friend, I may not need 
> > to list an Organization for them. 
> > (3) I would like to support multiple connection types - e.g. following, 
> > employer, etc. 
> > 
> > So, here is my apps models.py file: 
> >   
> > 
> > from django.db import models 
> > 
> > 
>
>

-- 
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/32dfa22a-0a55-4fdf-9da0-73152b1223aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using django login functionality in a non django app

2016-04-26 Thread Gergely Polonkai
That’s not a big issue if you really communicate with Django via a
web-based API. If the user can’t log in, you can simply redirect them to a
web page. I don’t see the need for user admin functions, though.



Gergely Polonkai
[image: https://]about.me/gergely.polonkai


2016-04-26 13:10 GMT+02:00 Larry Martell :

> Well, the issue with simply implementing auth, is that we'd need to
> not only implement login, which is easy, but also forgot password, and
> all the user admin functions. Since we have that already with django I
> want to leverage that and not reinvent the wheel.
>
> On Tue, Apr 26, 2016 at 2:29 AM, Gergely Polonkai 
> wrote:
> > Now I somewhat understand what falcon is, I suggest that you simply
> > implement auth on you web app (it seems to me there is none or little
> right
> > now. Of course, you don't have to protect all iour views, or you may
> want to
> > display a different dataset, but that's another topic.
> >
> > When that is done, you have to do two things in your Qt app. First, make
> > sure that when the server says that you are not authorized, pop up a
> login
> > window. After a successful login, store the user's credentials for later
> > use. What type of authentication to use and what to store is up to your
> > decision: HTTP Basic (store user/password), HTTP session (store the
> session
> > cookie) or token (store the token) based auths are the most common
> examples.
> >
> > Best,
> > Gergely
> >
> > On Apr 26, 2016 00:09, "Larry Martell"  wrote:
> >>
> >> The Qt app talks to the server with web requests routed to python code
> >> by falcon. It currently has no authentication/authorization of any
> >> kind. It's not a web app, you can't just navigate to any page, you can
> >> only get to parts of the app the code lets you get to.
> >>
> >> The way I envision it (if possible) is that I would have a decorator
> >> just like @login_required, and if that is called and the user is not
> >> logged in, it would invoke the django login page - just like it works
> >> in django. I think I can do most of this, the part I am unclear on is
> >> how I get control from the django login page back to the Qt app.
> >>
> >> On Mon, Apr 25, 2016 at 5:26 PM, Gergely Polonkai 
> >> wrote:
> >> > Hello,
> >> >
> >> > this all depends on how this Qt app communicates with the other end
> >> > (server
> >> > side). Does it offer *any* kind of authentication/authorization? If
> so,
> >> > look
> >> > for ways to integrate it with Django. If not, you are screwed anyway
> >> > (from
> >> > security point of view), because even if your app pops up a login
> >> > screen,
> >> > there can (and will) be ways to get around it.
> >> >
> >> > Best,
> >> > Gergely
> >> >
> >> > On Apr 25, 2016 22:37, "Larry Martell" 
> wrote:
> >> >>
> >> >> We have an existing django app with login, change password, and
> forgot
> >> >> password functionality.
> >> >>
> >> >> Then we have this other app built with the falcon framework. The
> >> >> client side of that is C++/Qt. That app has no login functionality -
> >> >> you bring it up and you're in. We would like to somehow use the login
> >> >> functionality of the django app in the falcon app. Is that even
> >> >> possible? I was thinking that in the Qt app I could bring up the
> >> >> django login page by invoking the URL for that app. But once they log
> >> >> in, how could I get control back to the Qt app and not have it
> proceed
> >> >> to the django app?
> >> >>
> >> >> Does this even make any sense? Has anyone ever done anything like
> 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACwCsY6_P7B7PZK6PRCt%3D2m0JyQ%2BejcMLp-1Q%2B7C2N-5rfyxZg%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/CACczBUJF7654A-dgJ5-JwYsi_WXdPnusnknT83iRqgT59iw9XQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using django login functionality in a non django app

2016-04-26 Thread Larry Martell
Well, the issue with simply implementing auth, is that we'd need to
not only implement login, which is easy, but also forgot password, and
all the user admin functions. Since we have that already with django I
want to leverage that and not reinvent the wheel.

On Tue, Apr 26, 2016 at 2:29 AM, Gergely Polonkai  wrote:
> Now I somewhat understand what falcon is, I suggest that you simply
> implement auth on you web app (it seems to me there is none or little right
> now. Of course, you don't have to protect all iour views, or you may want to
> display a different dataset, but that's another topic.
>
> When that is done, you have to do two things in your Qt app. First, make
> sure that when the server says that you are not authorized, pop up a login
> window. After a successful login, store the user's credentials for later
> use. What type of authentication to use and what to store is up to your
> decision: HTTP Basic (store user/password), HTTP session (store the session
> cookie) or token (store the token) based auths are the most common examples.
>
> Best,
> Gergely
>
> On Apr 26, 2016 00:09, "Larry Martell"  wrote:
>>
>> The Qt app talks to the server with web requests routed to python code
>> by falcon. It currently has no authentication/authorization of any
>> kind. It's not a web app, you can't just navigate to any page, you can
>> only get to parts of the app the code lets you get to.
>>
>> The way I envision it (if possible) is that I would have a decorator
>> just like @login_required, and if that is called and the user is not
>> logged in, it would invoke the django login page - just like it works
>> in django. I think I can do most of this, the part I am unclear on is
>> how I get control from the django login page back to the Qt app.
>>
>> On Mon, Apr 25, 2016 at 5:26 PM, Gergely Polonkai 
>> wrote:
>> > Hello,
>> >
>> > this all depends on how this Qt app communicates with the other end
>> > (server
>> > side). Does it offer *any* kind of authentication/authorization? If so,
>> > look
>> > for ways to integrate it with Django. If not, you are screwed anyway
>> > (from
>> > security point of view), because even if your app pops up a login
>> > screen,
>> > there can (and will) be ways to get around it.
>> >
>> > Best,
>> > Gergely
>> >
>> > On Apr 25, 2016 22:37, "Larry Martell"  wrote:
>> >>
>> >> We have an existing django app with login, change password, and forgot
>> >> password functionality.
>> >>
>> >> Then we have this other app built with the falcon framework. The
>> >> client side of that is C++/Qt. That app has no login functionality -
>> >> you bring it up and you're in. We would like to somehow use the login
>> >> functionality of the django app in the falcon app. Is that even
>> >> possible? I was thinking that in the Qt app I could bring up the
>> >> django login page by invoking the URL for that app. But once they log
>> >> in, how could I get control back to the Qt app and not have it proceed
>> >> to the django app?
>> >>
>> >> Does this even make any sense? Has anyone ever done anything like 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY6_P7B7PZK6PRCt%3D2m0JyQ%2BejcMLp-1Q%2B7C2N-5rfyxZg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Support Please

2016-04-26 Thread Daniele Procida
On Tue, Apr 26, 2016, Katie Chubb  wrote:

>I need to get in contact with someone who can help me make changes to the 
>client facing home page. I am new to the marketing role at the company and 
>the details have not been passed on. Is there anyone who can help me with 
>this? 

Without knowing details of your system, it's impossible to offer much useful 
advice.

If your site is running Django, you will typically be able to log in to the 
admin at /admin (i.e. append "/admin" to the address of the site in your 
browser).

But, you will need a username and password to proceed any further than that.

If your site runs a well-known Django application, then you may be able to get 
some help about using it. 

However, you need with some urgency to get hold of as much information as 
possible from the previous site manager, and to find out who set up the site in 
the first place.

Daniele

-- 
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/20160426104942.1437945901%40mail.wservices.ch.
For more options, visit https://groups.google.com/d/optout.


Support Please

2016-04-26 Thread Katie Chubb
Hi 
I need to get in contact with someone who can help me make changes to the 
client facing home page. I am new to the marketing role at the company and 
the details have not been passed on. Is there anyone who can help me with 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c8fe648f-0e5b-4200-ab39-2f951054ee3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.9 Apps aren't loaded yet

2016-04-26 Thread marcin . j . nowak


On Monday, April 25, 2016 at 11:44:20 PM UTC+2, marcin@gmail.com wrote:
 

> Just wondering about possibility to do some kind of late initialization.


I've found Dectate  library as a example 
of deferring configuration phase. 
I'm not talking about using it directly, but to familize with the concept.

Dectate is based on decorators, but applying the idea to metaclasses 
shouldn't be a problem.

The whole thing lies in registering defered intializers (model/app 
initializers in Django) and scan() config at the end of intitalization 
phase.

Marcin

-- 
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/f40b3c1f-ce85-4e97-8039-2e0cc304f680%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help with defining Models for ManyToMany and OneToMany relationships...

2016-04-26 Thread Bruce Whealton
OK, for starters, I understand the need for Null=True and blank=True.  So, 
jumping down...Not sure a better way to do this
but I will leave my comments for reference including my models and then 
respond to the questions
So sorry for my delay, I wasn't well this past weekend.


>>
>> My problems are (1) I cannot create connections without specifying a 
>> contact.  
>> (2) If I was adding a contact using the admin interface, how do I allow 
>> no value for that foreign field
>> or allow for some kind of ajax type of text completion?  If a person is 
>> family or friend, I may not need
>> to list an Organization for them.
>> (3) I would like to support multiple connection types - e.g. following, 
>> employer, etc.
>>
>> So, here is my apps models.py file:
>> 
>>
>> from django.db import models
>>
>>
>> class Contact(models.Model):
>> name = models.CharField(max_length=40)
>> Organization = models.CharField(max_length=50)
>> street_line1 = models.CharField("Street Line 1", max_length=50)
>> street_line2 = models.CharField("Street Line 2", max_length=50)
>> city = models.CharField(max_length=40)
>> state = models.CharField(max_length=40)
>> zipcode = models.CharField(max_length=20, blank=True, null=True)
>> phone1 = models.CharField(max_length=20)
>> phone2 = models.CharField(max_length=20)
>> email = models.EmailField(max_length=60)
>>
>>
>> class Organization(models.Model):
>> name = models.CharField(max_length=60)
>> street_line1 = models.CharField("Street Line 1", max_length=50)
>> street_line2 = models.CharField("Street Line 2", max_length=50)
>> city = models.CharField(max_length=40)
>> state = models.CharField(max_length=40)
>> zipcode = models.CharField(max_length=20, blank=True, null=True,)
>> phone = models.CharField(max_length=20)
>> email = models.EmailField(max_length=60)
>> website = models.URLField(max_length=90)
>> contact_name = models.ForeignKey(Contact, on_delete=models.CASCADE)
>>
>>
>> class Connection(models.Model):
>> type = models.CharField(max_length=60)
>> contact_name = models.ManyToManyField(Contact)   
>>
>> >>>
>>
>>
> Hi,
> 1.  Do django model fields default to required unless you use blank=True, 
> null=True?
> This may help you understand that: 
> http://stackoverflow.com/questions/8609192/differentiate-null-true-blank-true-in-django
>
> 2. I think you need a foreign key on Contact to Organization:
>
> class Contact(models.Model):
> name = 
> 
> organization = models.ForeignKey('Organization', null=True, blank=True)
>
> That way you can have many contacts to a single organization. The 
> contact_name in Organizations allows only 1 Contact, but you said you need 
> many.
>
>>> 
Ok that makes sense, I need a foreign key on the Contact table to link to 
the Organization.  I am not sure how easy it will be to show the results 
both ways 
that is ask for Contacts and see Orgs, or ask for Orgs and see all Contacts 
with the Org.  

>
> 3. I cannot create connections without specifying a contact.
> I don't see why not. Do you get any error?
>

This is something I thought people might say, "why do you want to do this?" 
 On Google Circles, you don't create circles typically and insert people 
into them.
Anyway, It seems to require that I pick a contact when I am creating a 
Connection.  Note, I used "connection" as a similar term to the way Google 
Plus uses "Circles" 
as that app seems to work well for me.  I will try again and see if it lets 
me save the connection without listing a contact. 
 

> 4. If I was adding a contact using the admin interface, how do I allow no 
> value for that foreign field
> By setting null=True, blank=True for the ForeignKey field. Notice Contact 
> do not have any ForeignKey in your example.
>
>>>
As you stated, I do need to have a ForeignKey within Contacts probably for 
both Organizations and Connection tables. 

>
> 5. or allow for some kind of ajax type of text completion?
> I have used this in the past: 
> https://django-autocomplete-light.readthedocs.org/en/master/ 
> 
>
> 6.  I would like to support multiple connection types - e.g. following, 
> employer, etc.
> You already have a 'type' field in Connections model. First I suggest to 
> use a different name for the field: type is a reserved Python word.
> Second, you can add choices to the field.
>
> from django.utils.translation import ugettext as _
> ...
> class Connection(models.Model):
> CHOICES = (('follower', _('Follower')),
>('employer', _('Employer')),
>('unspecified', _('Unspecified')),
>   )
> connection_type = models.CharField(max_length=20, choices=CHOICES)
> contact_name = models.ManyToManyField(Contact)  
>
> OK, that sounds great.  I debated over using choices but I can 

Django rest registration

2016-04-26 Thread nitish patkar
I am using Django-rest-auth (https://github.com/Tivix/django-rest-auth) in 
my django project for login and registration. I see a default registration 
form as in attached file.

Currently I am being able to register a new user with email instead of 
username. The default auth_user table in my MySql database has following 
columns: (id, password,last_login, is_superuser, username, first_name, 
last_name, email, is_staff, is_active, date_joined)

My settings.py :

INSTALLED_APPS = 
('django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','django.contrib.sites','rest_framework',#Rest-auth'rest_framework.authtoken','rest_auth',#Rest-auth
 registration'allauth','allauth.account','rest_auth.registration',#Following is 
added to allow cross domain requests i.e. for serving requests those are coming 
from frontend app 'corsheaders','flights',)


I want modify my registration form to have first name and last name with 
above fields so that when I register a new user, those two columns are also 
populated with first_name & last_name. Currently I have no additional view 
for registration nor any custom user model, I am simply using API endpoints 
provided by django-rest-auth.

*How can I 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d44aae09-2e46-468c-b614-ad7ed26ec204%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


New to Django (stuck at the end of the tutorial)

2016-04-26 Thread Cronos Cto



Hello Django Lovers.

So I started on Django as project of mine. Seems like a great first 
framework to start on. At the moment I am stuck at this:



This was after what I encountered at the end of the Django oficial post app 
tutorial.

I tried several ways to solve it. The problem seems to lay in the url.py 
file, but I can not seem to solve it.



Thank you to anyone that can help me solve 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ebf5ef21-550b-4f59-89bb-261584a7124c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


emailuser accessor clash after migrating to Django 1.6

2016-04-26 Thread schaf . mh
HI All,
In an existing project I got the following error after upgrading to Django 
1.6.11
CommandError: One or more models did not validate:
emailuser.emailuser: Accessor for m2m field 'groups' clashes with related 
m2m field 'Group.user_set'. Add a related_name argument to the definition 
for 'groups'.
emailuser.emailuser: Accessor for m2m field 'user_permissions' clashes with 
related m2m field 'Permission.user_set'. Add a related_name argument to the 
definition for 'user_permissions'.
auth.user: Accessor for m2m field 'groups' clashes with related m2m field 
'Group.user_set'. Add a related_name argument to the definition for 'groups'
.
auth.user: Accessor for m2m field 'user_permissions' clashes with related 
m2m field 'Permission.user_set'. Add a related_name argument to the 
definition for 'user_permissions'.

After reading some docs, I was enabling the:
AUTH_USER_MODEL = "emailuser.EmailUser"
and the unitTests were running.

BUT, the DB tables created for the unit test look completely different then 
for the original project, which I plan to upgrade.
In the original DB schema I have the following tables
auth_group
auth_group_permissions
auth_permission
auth_user
auth_user_groups
auth_user_user_permissions
django_admin_log
django_content_type
django_select2_keymap
django_session
emailuser_emailuser
emailuser_emailuser_groups
emailuser_emailuser_user_permissions
emailuser_passwordreset

whereas the following tables are missing in the unit test DB when using 
AUTH_USER_MODEL = "emailuser.EmailUser

Missing tables:
auth_user
auth_user_groups
auth_user_user_permissions

For the emailuser I was using the django-libtech-emailuser==0.2., but this 
was already used in the original installation.

Now I have multiple questions:
1.) Why do I get these CommandError, when it was already working in the old 
installation? Or is it possible that the DB schema was generated with other 
settings then in the final settings.py? 
2.) Accoring to my 'newbie' knowledge it is not a good idea to change the 
AUTH_USER_MODEL after first DB was released. How can I get the rid of the 
error mentioned above without changing the AUTH_USER_MODEL (which is not 
set in the original settings.py)?
3.) Why are the tables auth_user, auth_user_groups and 
auth_user_user_permissions not generated?
4.) Does it make sense to stick with emailuser lib, if I would like to 
migrate to Django 1.8 or 1.9? Or was this lib finally integrated?

Thanks for any hints.
Marcel

-- 
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/5bbec7a3-0583-43e5-8847-15612a207986%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: FieldError: Invalid order_by arguments: ['- pub_date']

2016-04-26 Thread Michal Petrucha
On Mon, Apr 25, 2016 at 08:49:47AM -0700, gu99r...@student.chalmers.se wrote:
> Ok, I looked at the tutorial page more closely. When you look at the code, 
> it looks like there is a space after the minus sign, especially when you 
> mark text. But if I copy and paste the text into some arbitrary text 
> editor, there is no space after the minus. When I follow the tutorial, I 
> prefer to type everything manually by hand as I believe I learn more 
> efficiently that way.

Oh, that's unfortunate, typing all samples manually instead of blindly
copy-pasting is certainly encouraged. The docs use a webfont for them,
so they are supposed to look the same everywhere, and with the default
“Fira Mono” it doesn't look like there's a space.

I'm curious – could you share a screenshot of what the code samples
look like in your browser? Could you also look in the developer tools
of your browser what font is actually being used? (In Chromium-based
browsers, you have to inspect the element containing the string, open
the computed styles, and it will show you what font was used.)

> When using "/polls/{{ question.id }}/" it doesn't work for me. In fact, the 
> url turns into "http://127.0.0.1:8000/polls/polls/...; on my local host.

That shouldn't happen – are you sure that you used "/polls/{{ question.id }}/", 
not "polls/{{ question.id }}/" without the leading slash?

Cheers,

Michal

-- 
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/20160426072202.GN435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: Using django login functionality in a non django app

2016-04-26 Thread Gergely Polonkai
Now I somewhat understand what falcon is, I suggest that you simply
implement auth on you web app (it seems to me there is none or little right
now. Of course, you don't have to protect all iour views, or you may want
to display a different dataset, but that's another topic.

When that is done, you have to do two things in your Qt app. First, make
sure that when the server says that you are not authorized, pop up a login
window. After a successful login, store the user's credentials for later
use. What type of authentication to use and what to store is up to your
decision: HTTP Basic (store user/password), HTTP session (store the session
cookie) or token (store the token) based auths are the most common examples.

Best,
Gergely
On Apr 26, 2016 00:09, "Larry Martell"  wrote:

> The Qt app talks to the server with web requests routed to python code
> by falcon. It currently has no authentication/authorization of any
> kind. It's not a web app, you can't just navigate to any page, you can
> only get to parts of the app the code lets you get to.
>
> The way I envision it (if possible) is that I would have a decorator
> just like @login_required, and if that is called and the user is not
> logged in, it would invoke the django login page - just like it works
> in django. I think I can do most of this, the part I am unclear on is
> how I get control from the django login page back to the Qt app.
>
> On Mon, Apr 25, 2016 at 5:26 PM, Gergely Polonkai 
> wrote:
> > Hello,
> >
> > this all depends on how this Qt app communicates with the other end
> (server
> > side). Does it offer *any* kind of authentication/authorization? If so,
> look
> > for ways to integrate it with Django. If not, you are screwed anyway
> (from
> > security point of view), because even if your app pops up a login screen,
> > there can (and will) be ways to get around it.
> >
> > Best,
> > Gergely
> >
> > On Apr 25, 2016 22:37, "Larry Martell"  wrote:
> >>
> >> We have an existing django app with login, change password, and forgot
> >> password functionality.
> >>
> >> Then we have this other app built with the falcon framework. The
> >> client side of that is C++/Qt. That app has no login functionality -
> >> you bring it up and you're in. We would like to somehow use the login
> >> functionality of the django app in the falcon app. Is that even
> >> possible? I was thinking that in the Qt app I could bring up the
> >> django login page by invoking the URL for that app. But once they log
> >> in, how could I get control back to the Qt app and not have it proceed
> >> to the django app?
> >>
> >> Does this even make any sense? Has anyone ever done anything like 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 https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACwCsY5NrpmqBKjEcrvFEFLKiz%3D0DyL4oGueUKDvb37wZTO6Gg%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/CACczBU%2BbBHCzn-U_gEmoYFF%2BVz8vQNkhnMiGp-mv4Dn7_5BmJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.