Re: query values() calls don't use transforms as filter() does

2016-08-18 Thread Tim Graham
I merged support for expressions in values() a few hours ago: 
https://github.com/django/django/commit/39f35d4b9de223b72c67bb1d12e65669b4e1355b

If that doesn't meet your needs, can you give an idea of what the QuerySet 
you want would look like?

On Thursday, August 18, 2016 at 5:10:41 PM UTC-4, Rishi Graham wrote:
>
> I noticed that the jsonb field indexing in postgres which is so handy in 
> filtering does not seem to extend to calls to values().  After digging 
> around a bit, it seems that sql.query.get_transform() is only called when 
> building a filter, but not when adding fields for a values call. 
>
> Using transforms in both places was mentioned as part of the now closed 
> feature request, #21863, which states that the "values() call will use 
> always get_transform() so .values('hstorefield__exact') will work 
> correctly”.   This was a little confusing because values does not use 
> “lookup”, which seems to refer only to the comparison type extension in the 
> filter string, but I am still relatively new to django so maybe I’m missing 
> something. 
>
> I don’t see evidence of any further discussion of the effect on values 
> calls.  Anyone know if this was on purpose, or just an oversight? 
>
> Thanks, 
> -Rishi.

-- 
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/674cac45-f4ef-4d9b-89f6-170264fc2ad3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django query not returning all objects

2016-08-18 Thread Koonal Bharadwaj
Hi Todor,

I have implemented something similar:

cases = HeartFlowCase.objects.all().annotate(Count('hf_id', distinct=True))


I also tried your suggestion and both seem to produce the same results. The 
number of duplicates is minimized but not removed entirely. Also the same 
problem when applying it to pagination still persists. 

Thanks for the suggestion. 


On Wednesday, August 17, 2016 at 11:20:34 PM UTC-7, Todor Velichkov wrote:
>
> Another solution would be to annotate min/max deadline date and order by 
> the annotation. Something like:
>
> cases = HeartFlowCase.objects.all().annotate(min_deadline=Min(
> 'data__deadline')).order_by('min_deadline')
>

-- 
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/5a4937c7-72f8-4e1e-844a-6ae607abbc61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django query not returning all objects

2016-08-18 Thread Koonal Bharadwaj
Hi Constantine,

Thanks for the quick reply. 

No luck with distinct. I tried that before (cases = cases.distinct() ), 
right after the order_by but it seems to have no effect, returning multiple 
duplicates.


On Wednesday, August 17, 2016 at 9:59:19 PM UTC-7, Constantine Covtushenko 
wrote:
>
> Hi Koonal,
>
> As said in django doc 
>  you 
> can use `distinct()` to remove duplicated rows from first query.
>
> I believe with this your pagination should works as expected.
>
> Regards,
>
>
> On Thu, Aug 18, 2016 at 2:58 AM, Koonal Bharadwaj  > wrote:
>
>> Hello,
>>
>> The issue:
>>
>> When trying to order_by on a related model duplicate entries are created. 
>> I solved this with an OrderedSet that is applied after paginating (
>> http://code.activestate.com/recipes/576694/). However, when I try to 
>> paginate the queryset, all the results are not returned. It's missing a few 
>> table rows. 
>>
>> Models:
>>
>> class HeartFlowCase(models.Model):
>> """
>>  
>> A Hearflow Case.
>>  
>> This serves at the true state of a case as it is processed through the 
>> system.
>> It also holds the results of each step of the processing.
>>
>> """
>>
>> # Primary
>> hf_id = models.CharField('HeartFlow ID', max_length=200, blank=True, 
>> unique=True)
>> canonical_data = models.ForeignKey('cases.CaseData', to_field='uuid', 
>> related_name="canonical_data")
>>
>>
>> class CaseData(models.Model):
>> """
>> Extracted and computed values related to a single processing run of a 
>> case.
>>
>> A HeartFlowCase can have multiple runs associated with it.
>> The one which is accepted to be the "clinically accurate" one is the one 
>> referred to as 'canonical_data' by
>> the HeartFlowCase itself.
>>
>> """
>>
>> # Primary
>> heartflowcase = models.ForeignKey(HeartFlowCase, related_name='data', 
>> blank=True, null=True)
>> uuid = models.CharField('Case Data UUID', max_length=200, blank=False, 
>> null=False, unique=True)
>> deadline = models.DateTimeField('Deadline', blank=True, 
>> default=get_default_deadline)
>>
>>
>> As you can see, there is a ForeignKey to canonical CaseData from 
>> HeartFlowCase and a ForeignKey to HeartFlowCase from CaseData. So you 
>> can have multiple CaseDatas per HeartFlowCase. 
>>
>> Structure:
>>
>> HeartFlowCase
>> |
>> data - CaseData1
>> \
>>  \ CaseData2
>>
>>
>> For example: 
>>
>> Total number of HeartFlow objects are 5 with 2 CaseDatas each. If I 
>> order_by deadline on CaseData as: 
>> cases = HeartFlowCase.objects.all().order_by(data__deadline)
>> this returns duplicates since there are multiple CaseDatas, which is 
>> fine. Now I try and paginate it by applying:
>>
>> paginator = Paginator(cases, 2)
>> cases = paginator.page(1)
>>
>> Now the SQL query has a LIMIT and OFFSET given. If the order_by gives 
>> duplicate HeartFlowCase objects this hits the LIMIT number and the results 
>> that are returned are missing a HeartFlowCase object. So if 2 duplicates are 
>> returned per case after applying the OrderedSet I get only one case back and 
>> missing one case since it was never returned from the database. As I goto 
>> the next page:
>>
>> cases = paginator.page(2)
>>
>> that missingHeartFlowCase object that was not returned from the first page 
>> queryset is lost forever and is never displayed. 
>>
>>
>> I hope this is clear. Please let me know if I can clarify further. Any help 
>> would greatly be appreciated. Thanks.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/61ec03f6-3325-49fe-bcdc-a7ca50784dc0%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/c8b199a1-daad-43e7-8b45-8b57b3b64dda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


query values() calls don't use transforms as filter() does

2016-08-18 Thread Rishi Graham
I noticed that the jsonb field indexing in postgres which is so handy in 
filtering does not seem to extend to calls to values().  After digging around a 
bit, it seems that sql.query.get_transform() is only called when building a 
filter, but not when adding fields for a values call.

Using transforms in both places was mentioned as part of the now closed feature 
request, #21863, which states that the "values() call will use always 
get_transform() so .values('hstorefield__exact') will work correctly”.   This 
was a little confusing because values does not use “lookup”, which seems to 
refer only to the comparison type extension in the filter string, but I am 
still relatively new to django so maybe I’m missing something.

I don’t see evidence of any further discussion of the effect on values calls.  
Anyone know if this was on purpose, or just an oversight?

Thanks,
-Rishi.

-- 
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/5C557351-59AF-450A-A69A-56821E215EB6%40soe.ucsc.edu.
For more options, visit https://groups.google.com/d/optout.


Re: How to have Multiple models in Admin View

2016-08-18 Thread ludovic coues
You should add a foreign key to language on translation. To save the
language from the dropbox.

Then I would create a ModelAdmin and set the form value. If I remember
correctly, the save method is on the form and you could save new objet
for each word at the same time as saving the translation object.

It will definitely be a bit tricky and involve a bit of digging in the
documentation.

Or maybe there is a package doing that already you could use but I
don't know of such thing.

2016-08-18 21:28 GMT+02:00 Hanh Kieu :
> I'm a little new to django.
> I would like to display multiple models in one admin view in django.
> when I do this:
>
> admin.site.register(Language)
> admin.site.register(Word)
> admin.site.register(Translation)
>
>
> b
>
> It would register 3 different models.
>
> My models look like this (this is for a dictionary app by the way):
>
>
> class Language(models.Model):
> language_text = models.CharField(max_length=200)
>
> def __str__(self):
> return self.language_text
>
>
> class Word(models.Model):
> language = models.ForeignKey(Language, on_delete=models.CASCADE)
> word_text = models.CharField(max_length=200)
>
> def __str__(self):
> return self.word_text
>
>
> class Translation(models.Model):
> word1 = models.OneToOneField(Word, on_delete=models.CASCADE,
> related_name="Translation_word1")
> word2 = models.OneToOneField(Word, on_delete=models.CASCADE,
> related_name="Translation_word2")
>
> def __str__(self):
> return self.word1.word_text
>
>
> I would like it to have an admin view where you would INPUT two words in a
> text box, choose the languages from a dropdown and click save, and it would
> create a translation for those words.
>
>
>
>
>
> How do I go about doing 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/a1feef39-bc6c-4b07-b43e-7e60deb48bfe%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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/CAEuG%2BTbaUMMgdPZ9sP_1kqS1EVHH%3DiZDhQ3qbZbstVcqZ76OjA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to have Multiple models in Admin View

2016-08-18 Thread Hanh Kieu
I'm a little new to django.
I would like to display multiple models in one admin view in django.
when I do this:

admin.site.register(Language)
admin.site.register(Word)
admin.site.register(Translation)


b

It would register 3 different models.

My models look like this (this is for a dictionary app by the way):


class Language(models.Model):
language_text = models.CharField(max_length=200)

def __str__(self):
return self.language_text


class Word(models.Model):
language = models.ForeignKey(Language, on_delete=models.CASCADE)
word_text = models.CharField(max_length=200)

def __str__(self):
return self.word_text


class Translation(models.Model):
word1 = models.OneToOneField(Word, on_delete=models.CASCADE, 
related_name="Translation_word1")
word2 = models.OneToOneField(Word, on_delete=models.CASCADE, 
related_name="Translation_word2")

def __str__(self):
return self.word1.word_text


I would like it to have an admin view where you would INPUT two words in a text 
box, choose the languages from a dropdown and click save, and it would create a 
translation for those words.



 How do I go about doing 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/a1feef39-bc6c-4b07-b43e-7e60deb48bfe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to get tests to work

2016-08-18 Thread Matt
Sorry replied to the wrong thread: https://dpaste.de/OF8j

On Wednesday, August 17, 2016 at 11:16:27 PM UTC-6, Gergely Polonkai wrote:
>
> Hello,
>
> this “refreshes.backups.tests” thing bothers me a lot. Could you show us 
> your directory structure, please?
>
> Best,
> Gergely 
>
> On Wed, Aug 17, 2016, 23:03 Matt  wrote:
>
>> Ok a step forward. When I spell out the tests it works: 
>>
>> https://dpaste.de/2MXf
>>
>> But when I run test without arguments, it fails out:
>>
>> https://dpaste.de/cgTH
>>
>> There is more than the backups app here, but I plan to replicate out the 
>> fix when I get it.
>>
>> On Wednesday, August 17, 2016 at 2:34:45 PM UTC-6, Fred Stluka wrote:
>>
>>> Matt,
>>>
>>> Oops!  Right.  I just noticed that in the dpaste.
>>>
>>> My next guess is you may need to change the name "good_index_text"
>>> to something that starts with "test_" to get it to be recognized as a 
>>> test.
>>>
>>> Or maybe something to do with "refreshes"?  The test trace shows
>>> it trying to run testcase "refreshes.backups.tests", but in the manual
>>> import you did from the python shell, you only import "backups.tests"
>>>
>>> --Fred 
>>> --
>>>
>> Fred Stluka -- mailt...@bristle.com -- http://bristle.com/~fred/ 
>>> Bristle Software, Inc -- http://bristle.com -- Glad to be of service! 
>>> Open Source: Without walls and fences, we need no Windows or Gates. 
>>> --
>>>
>>> On 8/17/16 4:27 PM, Matt wrote:
>>>
>> Sorry for the typo, but I have already do that way. I have the output in 
>>> the the first link.
>>>
>>> On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote: 

 Matt,

 Drop the "s" from "tests":

 ./manage.py test backups

 --Fred 
 --
 Fred Stluka -- mailt...@bristle.com -- http://bristle.com/~fred/ 
 Bristle Software, Inc -- http://bristle.com -- Glad to be of service! 
 Open Source: Without walls and fences, we need no Windows or Gates. 
 --

 On 8/17/16 4:17 PM, Matt wrote:

 When I'm trying to get tests to work it simply states that its unable 
 to import .tests. I'm not sure what I'm missing here. Here is some 
 output please let me know if you need more: 

 ./manage.py tests backups
 https://dpaste.de/4U9C

 The test file:
 https://dpaste.de/bBZt
 -- 
 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/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.


 -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>>
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/404f7e22-6f34-4c0d-bfdd-f277f6fb7543%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 

Re: Odd problem: some database updates do not appear on other pages until server restart

2016-08-18 Thread bobhaugen
Yes, that's what I did. It worked for the form field.

But, still, how pervasive is this behavior? (That was the question in the 
message you answered).

On Thursday, August 18, 2016 at 2:18:00 PM UTC-5, Sergiy Khohlov wrote:
>
> Hello,
> This is trivial mistake. Use form.__init__ if you would like to change it 
> dynamically
>
> 18 серп. 2016 22:14 "bobhaugen"  пише:
>
>> Also, how pervasive is this behavior? Does it affect all querysets 
>> generated by model methods? I do that all over the place. This could be bug 
>> heaven!
>>
>> -- 
>> 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/16924d52-c9e7-4666-b80d-7baaa49e59e7%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/6b847f04-6112-4512-848c-57eb95ad8185%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Odd problem: some database updates do not appear on other pages until server restart

2016-08-18 Thread Sergiy Khohlov
Hello,
This is trivial mistake. Use form.__init__ if you would like to change it
dynamically

18 серп. 2016 22:14 "bobhaugen"  пише:

> Also, how pervasive is this behavior? Does it affect all querysets
> generated by model methods? I do that all over the place. This could be bug
> heaven!
>
> --
> 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/16924d52-c9e7-4666-b80d-7baaa49e59e7%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/CADTRxJOrnvSacsL%2Bseok_PP-QnGdFo%2B-%3DMNU-ESd_ugpzSdUyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Odd problem: some database updates do not appear on other pages until server restart

2016-08-18 Thread bobhaugen
Also, how pervasive is this behavior? Does it affect all querysets 
generated by model methods? I do that all over the place. This could be bug 
heaven!

-- 
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/16924d52-c9e7-4666-b80d-7baaa49e59e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Odd problem: some database updates do not appear on other pages until server restart

2016-08-18 Thread bobhaugen
Looks like it works if I "specify queryset=None when declaring the form 
field and then populate the queryset in the form’s__init__() method:"

Does that make sense to you?

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


Re: Odd problem: some database updates do not appear on other pages until server restart

2016-08-18 Thread bobhaugen
On Thursday, August 18, 2016 at 1:34:29 PM UTC-5, Tim Graham wrote:
>
> I'd guess you're doing a query for the form field's choices at the module 
> level which will be executed once and cached for as long as the server 
> runs. See if 
> https://docs.djangoproject.com/en/stable/ref/forms/fields/#fields-which-handle-relationships
>  
> helps, otherwise please post the code for the form in question.
>
> Ohhh, Tim! You might just have nailed it! Yes I am.

Here's the relevant code for the form field:
 
```
from_agent = forms.ModelChoiceField(
required=False,
queryset=EconomicAgent.objects.with_user(),
```

with_user() is a method of
class AgentManager(models.Manager)


 executed once and cached for as long as the server runs.
>

Is that behavior documented anywhere? Regardless, got any ideas how to 
avoid it?

But thank you very much for the likely suspect. 

-- 
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/b55a8386-fffa-44ca-8543-f512cc4fbc6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python dictionaries saved to models

2016-08-18 Thread Tim Graham
`apps` should be the first argument to the RunPython function. Using the 
import you mentioned is incorrect and may cause bugs if your models change 
in the future.

On Thursday, August 18, 2016 at 10:10:43 AM UTC-4, Aaron Weisberg wrote:
>
> Nevermind- the good folks at Django didn't add:
>
> from django.apps import apps in order to pull off this data migration
>
> On Thursday, August 18, 2016 at 8:40:26 AM UTC-5, Aaron Weisberg wrote:
>>
>> Thanks.  
>>
>> However, when I write the function and try to run the data migration I 
>> run into this error:
>>
>> Enter code here...NameError: name apps is not defined
>>
>> That is coming from this line in the migration:
>>
>> Players = apps.get_model("team","Players")
>>
>> This is a copy/paste from the documentation.  Is there a typo?
>>
>> Thanks.
>>
>>
>> On Thursday, August 18, 2016 at 7:48:58 AM UTC-5, Tim Graham wrote:
>>>
>>> Right, or even in a standalone script if a migration is more than you 
>>> need: 
>>> https://docs.djangoproject.com/en/stable/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage
>>>
>>> On Thursday, August 18, 2016 at 2:14:39 AM UTC-4, Todor Velichkov wrote:

 Maybe a data migration 
  
 is what you are looking for.

 On Thursday, August 18, 2016 at 8:38:33 AM UTC+3, Aaron Weisberg wrote:
>
> Great- thanks Tim.
>
> I understand the Python, but what I guess where I'm fuzzy is where to 
> exactly put that code.  
>
> Do I put it in the models.py? class.py?  and how do I execute?
>
> That is the final piece of the puzzle for me.  
>
> Thanks so much.
>
> Aaron
>
> On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote:
>>
>> You need to transform your data dictionary so that the keys match the 
>> models field names and then you can use:
>>
>> players_data = [{'number': 1, ...}, {...}]
>>
>> for data in players_data:
>> Player.objects.bulk_create(**data)
>>
>> (or something similar with bulk_create())
>>
>>
>> https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create
>>
>> On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg 
>> wrote:
>>>
>>> Hi everyone,
>>>
>>> I have several dictionaries that I would like to import into my 
>>> django project database, but I can't figure out exactly how.
>>>
>>> I have tried to implement through fixtures, through views and 
>>> through loaddata, but I must be doing something wrong at every turn- so 
>>> if 
>>> someone could suggest a workflow, it would really help me a lot!
>>>
>>> My data is currently in a list of dictionaries called data:
>>>
>>> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht'
>>> : 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 
>>> 'university', 'number': 10, 'exp': 1},
>>>
>>>
>>> each dictionary within that list is a "player" who I'd like to input 
>>> his data into my model "Players"
>>>
>>> Enter code here...
>>> #models.py
>>> class Player(models.Model):
>>>
>>> number = models.CharField(max_length=2)
>>> player = models.CharField(max_length=50)
>>> position = models.CharField(max_length=2)
>>> height = models.CharField(max_length=50)
>>> weight = models.CharField(max_length=50)
>>> birth = models.DateField()
>>> exp = models.CharField(max_length=50)
>>> college = models.CharField(max_length=50)
>>> def __str__(self):
>>> return self.player
>>>
>>>
>>> There are about 500 players in that list of dictionaries above that 
>>> I would like to insert into this model.
>>>
>>> 1) Can i run a function in the model above to insert the data into 
>>> its appropriate field?  If so, how do I execute that function?
>>> 2) If it's a view that I need to execute-  do I just put the 
>>> function in views.py?  How then is the dictionary imported into the 
>>> database?
>>>
>>> or... How would you go about getting that data into your database? 
>>>  Please note that the data is coming from a url that might change from 
>>> time 
>>> to time.  But I think once i get the first iteration of data into these 
>>> models I can figure out how to update.  But the only way I can figure 
>>> out 
>>> is to create them one by one in the shell or create a form and input 
>>> them 
>>> one by one.
>>>
>>> If you have a solution, please share and be as detailed as possible 
>>> since I am a complete beginner with django.
>>>
>>> Peace and love,
>>>
>>> Aaron
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving 

Re: Odd problem: some database updates do not appear on other pages until server restart

2016-08-18 Thread Tim Graham
I'd guess you're doing a query for the form field's choices at the module 
level which will be executed once and cached for as long as the server 
runs. See if 
https://docs.djangoproject.com/en/stable/ref/forms/fields/#fields-which-handle-relationships
 
helps, otherwise please post the code for the form in question.

On Thursday, August 18, 2016 at 12:54:15 PM UTC-4, bobhaugen wrote:
>
> I'm running django 1.8.14, I have an odd problem, that I have reproduced 
> both locally using runserver and sqlite, and also using Apache with 
> Postgres.
>
> I create a new model instance on one page, and go to another page where 
> that same object should appear in a form selection list. It does not.
>
> After I restart the server (both with runserver and Apache) it appears.
>
> I also see other places where the same odd behavior with template 
> variables showing  foreign key relationships, like {{ 
> object.foreign_key_field }}.
>
> This is not on all pages, just some. It happens in both of the situations 
> I mentioned above (form selection choices and template variables for 
> foreign key fields).
>
> I grepped for cache. None in my code, a lot in site-packages, but I have 
> no idea where to look and what to look for.
>
> I would gratefully follow any clues.
>
> 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/44c72a65-4082-408a-adf2-f1662e768563%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using hashids in django template

2016-08-18 Thread Paul Aswa
Thanks for the shedding light on filters, really helpful. I should have 
thought about that!

On Thursday, August 18, 2016 at 8:46:22 PM UTC+3, ludovic coues wrote:
>
> Filter are a way to apply a function to a value in a django template. 
>
> The filter would look like that: 
>
> def hashid(value): 
> return hashids.encode(value) 
>
> and your template like that: 
>
> {{ id|hashid }} 
>
> I omitted some part that are in the doc, like making the filter 
> available in your template. The doc have more information on the 
> subject. 
>
> 2016-08-18 19:37 GMT+02:00 Paul Aswa : 
> > Being a newbie to python and django, this seems to be giving me problems 
> > 
> > On Thursday, August 18, 2016 at 2:57:56 PM UTC+3, ludovic coues wrote: 
> >> 
> >> You might be looking for this 
> >> https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/ 
> >> 
> >> 2016-08-18 12:57 GMT+02:00 Paul Aswa : 
> >> > Is there means of encoding an id using hashids in django templates? 
> >> > 
> >> > -- 
> >> > 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/fd7df219-a31a-408c-bbeb-ca0162492106%40googlegroups.com.
>  
>
> >> > For more options, visit https://groups.google.com/d/optout. 
> >> 
> >> 
> >> 
> >> -- 
> >> 
> >> Cordialement, Coues Ludovic 
> >> +336 148 743 42 
> > 
> > -- 
> > 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/363aa415-da76-4670-a992-47ce4506449c%40googlegroups.com.
>  
>
> > 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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/a4195740-fcf5-4086-88db-d014f0489847%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using hashids in django template

2016-08-18 Thread ludovic coues
Filter are a way to apply a function to a value in a django template.

The filter would look like that:

def hashid(value):
return hashids.encode(value)

and your template like that:

{{ id|hashid }}

I omitted some part that are in the doc, like making the filter
available in your template. The doc have more information on the
subject.

2016-08-18 19:37 GMT+02:00 Paul Aswa :
> Being a newbie to python and django, this seems to be giving me problems
>
> On Thursday, August 18, 2016 at 2:57:56 PM UTC+3, ludovic coues wrote:
>>
>> You might be looking for this
>> https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/
>>
>> 2016-08-18 12:57 GMT+02:00 Paul Aswa :
>> > Is there means of encoding an id using hashids in django templates?
>> >
>> > --
>> > 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/fd7df219-a31a-408c-bbeb-ca0162492106%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>>
>> Cordialement, Coues Ludovic
>> +336 148 743 42
>
> --
> 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/363aa415-da76-4670-a992-47ce4506449c%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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/CAEuG%2BTYLXdrzWSTUaf0rfZuZcZnu1bSzi4SW2j61cqtgNuVMvg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using hashids in django template

2016-08-18 Thread Paul Aswa
Being a newbie to python and django, this seems to be giving me problems

On Thursday, August 18, 2016 at 2:57:56 PM UTC+3, ludovic coues wrote:
>
> You might be looking for this 
> https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/ 
>
> 2016-08-18 12:57 GMT+02:00 Paul Aswa : 
> > Is there means of encoding an id using hashids in django templates? 
> > 
> > -- 
> > 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/fd7df219-a31a-408c-bbeb-ca0162492106%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
>
> Cordialement, Coues Ludovic 
> +336 148 743 42 
>

-- 
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/363aa415-da76-4670-a992-47ce4506449c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Odd problem: some database updates do not appear on other pages until server restart

2016-08-18 Thread bobhaugen
I'm running django 1.8.14, I have an odd problem, that I have reproduced 
both locally using runserver and sqlite, and also using Apache with 
Postgres.

I create a new model instance on one page, and go to another page where 
that same object should appear in a form selection list. It does not.

After I restart the server (both with runserver and Apache) it appears.

I also see other places where the same odd behavior with template variables 
showing  foreign key relationships, like {{ object.foreign_key_field }}.

This is not on all pages, just some. It happens in both of the situations I 
mentioned above (form selection choices and template variables for foreign 
key fields).

I grepped for cache. None in my code, a lot in site-packages, but I have no 
idea where to look and what to look for.

I would gratefully follow any clues.

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/e3d375e3-dffd-43f7-a7ea-409a15e5381c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to get tests to work

2016-08-18 Thread Matt
Here you go:

https://dpaste.de/OF8j

On Wednesday, August 17, 2016 at 11:16:27 PM UTC-6, Gergely Polonkai wrote:
>
> Hello,
>
> this “refreshes.backups.tests” thing bothers me a lot. Could you show us 
> your directory structure, please?
>
> Best,
> Gergely 
>
> On Wed, Aug 17, 2016, 23:03 Matt  wrote:
>
>> Ok a step forward. When I spell out the tests it works: 
>>
>> https://dpaste.de/2MXf
>>
>> But when I run test without arguments, it fails out:
>>
>> https://dpaste.de/cgTH
>>
>> There is more than the backups app here, but I plan to replicate out the 
>> fix when I get it.
>>
>> On Wednesday, August 17, 2016 at 2:34:45 PM UTC-6, Fred Stluka wrote:
>>
>>> Matt,
>>>
>>> Oops!  Right.  I just noticed that in the dpaste.
>>>
>>> My next guess is you may need to change the name "good_index_text"
>>> to something that starts with "test_" to get it to be recognized as a 
>>> test.
>>>
>>> Or maybe something to do with "refreshes"?  The test trace shows
>>> it trying to run testcase "refreshes.backups.tests", but in the manual
>>> import you did from the python shell, you only import "backups.tests"
>>>
>>> --Fred 
>>> --
>>>
>> Fred Stluka -- mailt...@bristle.com -- http://bristle.com/~fred/ 
>>> Bristle Software, Inc -- http://bristle.com -- Glad to be of service! 
>>> Open Source: Without walls and fences, we need no Windows or Gates. 
>>> --
>>>
>>> On 8/17/16 4:27 PM, Matt wrote:
>>>
>> Sorry for the typo, but I have already do that way. I have the output in 
>>> the the first link.
>>>
>>> On Wednesday, August 17, 2016 at 2:24:19 PM UTC-6, Fred Stluka wrote: 

 Matt,

 Drop the "s" from "tests":

 ./manage.py test backups

 --Fred 
 --
 Fred Stluka -- mailt...@bristle.com -- http://bristle.com/~fred/ 
 Bristle Software, Inc -- http://bristle.com -- Glad to be of service! 
 Open Source: Without walls and fences, we need no Windows or Gates. 
 --

 On 8/17/16 4:17 PM, Matt wrote:

 When I'm trying to get tests to work it simply states that its unable 
 to import .tests. I'm not sure what I'm missing here. Here is some 
 output please let me know if you need more: 

 ./manage.py tests backups
 https://dpaste.de/4U9C

 The test file:
 https://dpaste.de/bBZt
 -- 
 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/89d6fac7-0848-4e35-8b4a-62d24178c3aa%40googlegroups.com
  
 
 .
 For more options, visit https://groups.google.com/d/optout.


 -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/django-users.
>>>
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/04fcacea-15d0-42af-afe5-424c2d1df86f%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/404f7e22-6f34-4c0d-bfdd-f277f6fb7543%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.

Re: Implementing django auth system with relational models

2016-08-18 Thread Shamaila Moazzam
ok thanx @  ludovic coues...
i will try this and then tell you
regards


On Thursday, August 18, 2016 at 2:38:46 AM UTC+5, ludovic coues wrote:
>
> Ok, sorry, I made a off by one error on the link :) 
>
> Try that: 
>
> # shops/admin.py 
> from django.contrib import admin 
> from products.models import Product 
> from .models import Shop 
>
> class ShopAdmin(admin.ModelAdmin): 
> def formfield_for_manytomany(self, db_field, request, **kwargs): 
> if db_field.name == "product": 
> kwargs["queryset"] = Product.objects.filter(user=request.user) 
> return super(ShopAdmin, 
> self).formfield_for_manytomany(db_field, request, **kwargs) 
>
> admin.site.register(Shop, ShopAdmin) 
>
> ### 
>
> It should give you the desired result 
>
> 2016-08-17 19:31 GMT+02:00 Shamaila Moazzam  >: 
> > 
> > shops/admin.py 
> > from .models import Shop 
> > 
> > admin.site.register(Shop) 
> > 
> > 
> > products/admin.py 
> > 
> > 
> > from .models import Product, Variation, ProductImage, Category, 
> > ProductFeatured, color_product, size_product 
> > 
> > 
> > 
> > class ProductImageInline(admin.TabularInline): 
> > model = ProductImage 
> > extra = 0 
> > max_num = 10 
> > 
> > class VariationInline(admin.TabularInline): 
> > model = Variation 
> > extra = 0 
> > max_num = 10 
> > 
> > 
> > class ProductAdmin(admin.ModelAdmin): 
> > list_display = ['__unicode__', 'price',] 
> > inlines = [ 
> > ProductImageInline, 
> > VariationInline, 
> > 
> > 
> > ] 
> > class Meta: 
> > model = Product 
> > 
> > 
> > admin.site.register(Product, ProductAdmin) 
> > 
> > 
> > 
> > 
> > #admin.site.register(Variation) 
> > 
> > admin.site.register(ProductImage) 
> > 
> > 
> > admin.site.register(Category) 
> > 
> > 
> > admin.site.register(ProductFeatured) 
> > 
> > admin.site.register(color_product) 
> > 
> > admin.site.register(size_product) 
> > 
> > On Wednesday, August 17, 2016 at 9:23:31 PM UTC+5, ludovic coues wrote: 
> >> 
> >> Could you share your admin.py file ? 
> >> 
> >> You might be interested into this part of the documentation: 
> >> 
> >> 
> https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey
>  
> >> 
> >> 2016-08-17 17:20 GMT+02:00 Shamaila Moazzam : 
> >> > @Ludovic there is no error. Just I don't want to get all the products 
> >> > pre-populated. I need empty products field and only when user uploads 
> >> > products then it should show me products. Please advise 
> >> > 
> >> > On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam 
> >> > wrote: 
> >> >> 
> >> >> Hi, 
> >> >> 
> >> >> I am a beginner and please forgive me if my question is not up to 
> the 
> >> >> standard. I've got two models one is Product which is saved in db 
> >> >> already 
> >> >> and another one is Shop. I am trying to related both models with 
> >> >> following 
> >> >> code. 
> >> >> 
> >> >> class Product(models.Model): 
> >> >> user = models.ForeignKey(settings.USER_AUTH_MODEL) 
> >> >> title = models.CharField(max_length=120) 
> >> >> description = models.TextField(blank=True, null=True) 
> >> >> price = models.DecimalField(decimal_places=2, max_digits=20) 
> >> >> publish_date = models.DateTimeField(auto_now=False, 
> >> >> auto_now_add=False, null=True, blank= True) 
> >> >> expire_date = models.DateTimeField(auto_now=False, 
> >> >> auto_now_add=False, 
> >> >> null=True, blank=True) 
> >> >> active = models.BooleanField(default=True) 
> >> >> categories = models.ManyToManyField('Category', blank=True) 
> >> >> default = models.ForeignKey('Category', 
> >> >> related_name='default_category', null=True, blank=True) 
> >> >> hitcounts = GenericRelation(HitCount, 
> >> >> content_type_field='content_type', object_id_field='object_pk',) 
> >> >> 
> >> >> 
> >> >> objects = ProductManager() 
> >> >> 
> >> >> 
> >> >> class Meta: 
> >> >> ordering = ["-title"] 
> >> >> 
> >> >> 
> >> >> def __unicode__(self): 
> >> >> return self.title 
> >> >> 
> >> >> 
> >> >> class Shop(models.Model): 
> >> >> product = models.ManyToManyField(Product) 
> >> >> 
> >> >> title = models.CharField(max_length=120, null=False) 
> >> >> image = models.ImageField(upload_to=image_upload_to_shop, 
> >> >> null=True) 
> >> >> location = models.CharField(max_length=120) 
> >> >> 
> >> >> 
> >> >> 
> >> >> 
> >> >> def __unicode__(self): 
> >> >> return str(self.title) 
> >> >> 
> >> >> 
> >> >> 
> >> >> 
> >> >> With above I've got it added in my admin.py for Shop app and now I 
> have 
> >> >> a 
> >> >> problem. When I add a shop it shows all the past products 
> prepopulated 
> >> >> in my 
> >> >> "products" field. 
> >> >> I just need to add the products that shop account holder has 
> uploaded. 
> >> >> I 
> >> >> wish to use django\s built-in auth model to register shop holders. 
> >> >> Again the 
> >> >> 

Re: Python dictionaries saved to models

2016-08-18 Thread Aaron Weisberg
Nevermind- the good folks at Django didn't add:

from django.apps import apps in order to pull off this data migration

On Thursday, August 18, 2016 at 8:40:26 AM UTC-5, Aaron Weisberg wrote:
>
> Thanks.  
>
> However, when I write the function and try to run the data migration I run 
> into this error:
>
> Enter code here...NameError: name apps is not defined
>
> That is coming from this line in the migration:
>
> Players = apps.get_model("team","Players")
>
> This is a copy/paste from the documentation.  Is there a typo?
>
> Thanks.
>
>
> On Thursday, August 18, 2016 at 7:48:58 AM UTC-5, Tim Graham wrote:
>>
>> Right, or even in a standalone script if a migration is more than you 
>> need: 
>> https://docs.djangoproject.com/en/stable/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage
>>
>> On Thursday, August 18, 2016 at 2:14:39 AM UTC-4, Todor Velichkov wrote:
>>>
>>> Maybe a data migration 
>>>  
>>> is what you are looking for.
>>>
>>> On Thursday, August 18, 2016 at 8:38:33 AM UTC+3, Aaron Weisberg wrote:

 Great- thanks Tim.

 I understand the Python, but what I guess where I'm fuzzy is where to 
 exactly put that code.  

 Do I put it in the models.py? class.py?  and how do I execute?

 That is the final piece of the puzzle for me.  

 Thanks so much.

 Aaron

 On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote:
>
> You need to transform your data dictionary so that the keys match the 
> models field names and then you can use:
>
> players_data = [{'number': 1, ...}, {...}]
>
> for data in players_data:
> Player.objects.bulk_create(**data)
>
> (or something similar with bulk_create())
>
>
> https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create
>
> On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg 
> wrote:
>>
>> Hi everyone,
>>
>> I have several dictionaries that I would like to import into my 
>> django project database, but I can't figure out exactly how.
>>
>> I have tried to implement through fixtures, through views and through 
>> loaddata, but I must be doing something wrong at every turn- so if 
>> someone 
>> could suggest a workflow, it would really help me a lot!
>>
>> My data is currently in a list of dictionaries called data:
>>
>> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': 
>> 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 
>> 'university', 'number': 10, 'exp': 1},
>>
>>
>> each dictionary within that list is a "player" who I'd like to input 
>> his data into my model "Players"
>>
>> Enter code here...
>> #models.py
>> class Player(models.Model):
>>
>> number = models.CharField(max_length=2)
>> player = models.CharField(max_length=50)
>> position = models.CharField(max_length=2)
>> height = models.CharField(max_length=50)
>> weight = models.CharField(max_length=50)
>> birth = models.DateField()
>> exp = models.CharField(max_length=50)
>> college = models.CharField(max_length=50)
>> def __str__(self):
>> return self.player
>>
>>
>> There are about 500 players in that list of dictionaries above that I 
>> would like to insert into this model.
>>
>> 1) Can i run a function in the model above to insert the data into 
>> its appropriate field?  If so, how do I execute that function?
>> 2) If it's a view that I need to execute-  do I just put the function 
>> in views.py?  How then is the dictionary imported into the database?
>>
>> or... How would you go about getting that data into your database? 
>>  Please note that the data is coming from a url that might change from 
>> time 
>> to time.  But I think once i get the first iteration of data into these 
>> models I can figure out how to update.  But the only way I can figure 
>> out 
>> is to create them one by one in the shell or create a form and input 
>> them 
>> one by one.
>>
>> If you have a solution, please share and be as detailed as possible 
>> since I am a complete beginner with django.
>>
>> Peace and love,
>>
>> Aaron
>>
>>

-- 
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/37ff8df2-c858-4108-9777-90bc385bb9a7%40googlegroups.com.
For more options, visit 

Re: Python dictionaries saved to models

2016-08-18 Thread Aaron Weisberg
Thanks.  

However, when I write the function and try to run the data migration I run 
into this error:

Enter code here...NameError: name apps is not defined

That is coming from this line in the migration:

Players = apps.get_model("team","Players")

This is a copy/paste from the documentation.  Is there a typo?

Thanks.


On Thursday, August 18, 2016 at 7:48:58 AM UTC-5, Tim Graham wrote:
>
> Right, or even in a standalone script if a migration is more than you 
> need: 
> https://docs.djangoproject.com/en/stable/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage
>
> On Thursday, August 18, 2016 at 2:14:39 AM UTC-4, Todor Velichkov wrote:
>>
>> Maybe a data migration 
>>  
>> is what you are looking for.
>>
>> On Thursday, August 18, 2016 at 8:38:33 AM UTC+3, Aaron Weisberg wrote:
>>>
>>> Great- thanks Tim.
>>>
>>> I understand the Python, but what I guess where I'm fuzzy is where to 
>>> exactly put that code.  
>>>
>>> Do I put it in the models.py? class.py?  and how do I execute?
>>>
>>> That is the final piece of the puzzle for me.  
>>>
>>> Thanks so much.
>>>
>>> Aaron
>>>
>>> On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote:

 You need to transform your data dictionary so that the keys match the 
 models field names and then you can use:

 players_data = [{'number': 1, ...}, {...}]

 for data in players_data:
 Player.objects.bulk_create(**data)

 (or something similar with bulk_create())


 https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create

 On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg wrote:
>
> Hi everyone,
>
> I have several dictionaries that I would like to import into my django 
> project database, but I can't figure out exactly how.
>
> I have tried to implement through fixtures, through views and through 
> loaddata, but I must be doing something wrong at every turn- so if 
> someone 
> could suggest a workflow, it would really help me a lot!
>
> My data is currently in a list of dictionaries called data:
>
> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': 
> 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 
> 'university', 'number': 10, 'exp': 1},
>
>
> each dictionary within that list is a "player" who I'd like to input 
> his data into my model "Players"
>
> Enter code here...
> #models.py
> class Player(models.Model):
>
> number = models.CharField(max_length=2)
> player = models.CharField(max_length=50)
> position = models.CharField(max_length=2)
> height = models.CharField(max_length=50)
> weight = models.CharField(max_length=50)
> birth = models.DateField()
> exp = models.CharField(max_length=50)
> college = models.CharField(max_length=50)
> def __str__(self):
> return self.player
>
>
> There are about 500 players in that list of dictionaries above that I 
> would like to insert into this model.
>
> 1) Can i run a function in the model above to insert the data into its 
> appropriate field?  If so, how do I execute that function?
> 2) If it's a view that I need to execute-  do I just put the function 
> in views.py?  How then is the dictionary imported into the database?
>
> or... How would you go about getting that data into your database? 
>  Please note that the data is coming from a url that might change from 
> time 
> to time.  But I think once i get the first iteration of data into these 
> models I can figure out how to update.  But the only way I can figure out 
> is to create them one by one in the shell or create a form and input them 
> one by one.
>
> If you have a solution, please share and be as detailed as possible 
> since I am a complete beginner with django.
>
> Peace and love,
>
> Aaron
>
>

-- 
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/56a0c926-853b-42ba-ae25-9fa24d6f3bd1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: New to Django

2016-08-18 Thread Derek
In your view you have:

context = {
"server_list": serverlist,
"image_list": imagelist,
"child_list": childimagelist
}

So the variables being passed through to your template are named: 
server_list, image_list, child_list.

In your template you call this:

for server, images in child_list.items
 
Which is fine, but then you call this:

for image, number in images.items

But there is no variable called "images" I think it should be 
"image_list:.

HTH
Derek


On Tuesday, 16 August 2016 02:22:28 UTC+2, Wolf Painter wrote:
>
> Hey everyone, I didn't see any posts (or google search) that could 
> possibly answer my question, so I am here... I'm trying to create a way to 
> launch vm's on a Xen or VMWare server using a website. I have the python 
> file written on the Server and am currently creating a DJango app to manage 
> everything. I'm stuck in a big way. I  currently have models that track 
> servers, images and child images launched from the parent, but I can't 
> figure out how to display it properly in a template so i can update the 
> count (either add or subtract a number of VM's from a server). I'm new to 
> both Django and Python, so please excuse any ignorance here... Here are my 
> relevant models:
>
> class Image(models.Model):
> name = models.CharField(verbose_name='Image Name', max_length=50)
> labID = models.ManyToManyField(Lab, blank=True, related_name='labID')
> type = models.CharField(max_length=50)
>
> def __str__(self):
> return self.name
>
>
> class Server(models.Model):
> name = models.CharField(verbose_name='Server Name', max_length=50)
> ipAddress = models.CharField(max_length=15)
> maxCCU = models.IntegerField(default=0)
> images = models.ManyToManyField(Image, blank=True, 
> related_name='baseImage')
>
> def __str__(self):
> return self.ipAddress
>
> class Childimage(models.Model):
> name = models.CharField(verbose_name='Child Image Name', max_length=50)
> parent = models.ForeignKey(Image, related_name='base')
> server = models.ForeignKey(Server, related_name='server')
> inUse = models.BooleanField()
> rdpportnum = models.CharField(max_length=4)
>
> def __str__(self):
> return self.name
>
> What I'm trying to do is have a web page that displays the number of parent 
> images on a server by counting the child image. For example, I have a parent 
> image called win2k12_excel and there are 12 child images of the parent 
> win2k12_excel on the x.x.x.x server. I would like a web page that shows there 
> are 12 win2k12_excel images on that server that would allow me to add or 
> subtract the number on that server.
>
>
> I have created a view that does this and puts it into a multidimensional 
> dictionary, but I cannot figure out how to get that to render properly in a 
> template. Here is my view:
>
>
> def servers(request):
> serverlist = Server.objects.all()
> imagelist = Image.objects.filter(baseImage__in=serverlist).distinct()
>
> childimagelist = defaultdict(list)
> for server in serverlist:
> for image in imagelist:
> number = 
> Childimage.objects.filter(parent__name__contains=image).filter(server__ipAddress__contains=server).count()
> childimagelist[server].append({image: number})
> childimagelist.default_factory = None
> context = {
> "server_list": serverlist,
> "image_list": imagelist,
> "child_list": childimagelist
> }
> return render(request, "administration/servers.html", context)
>
> No matter what I have tried so far, I cannot get this dictionary to render in 
> a template. Is there a better way to do what I'm trying to do? Is there a 
> proper way to get the dictionary parsed in the template? Any help would be 
> appreciated. 
>
>
> Oh, and I have search Google for weeks and tried all the suggestions I found. 
> None of them worked. I can get the first part of the dictionary parsed, but 
> no further than that. Here is the template code (server works, but for image, 
> number in images.items, does not):
>
>
> {% for server, images in child_list.items %}
> {{ server }}
> {% for image, number in images.items %}
> {{ number }}
> {% endfor %}
> {% endfor %}
>
>
>
> Any help at all would be appreciated...
>
>
> Thanks,
>
> Wolf
>
>

-- 
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/5050d618-f3a9-4f8b-ab99-520bd02e47d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models of Speedy Net

2016-08-18 Thread Uri Even-Chen
Thank you Asad and Avraham!


*Uri Even-Chen*
[image: photo] Phone: +972-54-3995700
Email: u...@speedy.net
Website: http://www.speedysoftware.com/uri/en/
  
    

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


Re: Python dictionaries saved to models

2016-08-18 Thread Tim Graham
Right, or even in a standalone script if a migration is more than you need: 
https://docs.djangoproject.com/en/stable/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage

On Thursday, August 18, 2016 at 2:14:39 AM UTC-4, Todor Velichkov wrote:
>
> Maybe a data migration 
>  
> is what you are looking for.
>
> On Thursday, August 18, 2016 at 8:38:33 AM UTC+3, Aaron Weisberg wrote:
>>
>> Great- thanks Tim.
>>
>> I understand the Python, but what I guess where I'm fuzzy is where to 
>> exactly put that code.  
>>
>> Do I put it in the models.py? class.py?  and how do I execute?
>>
>> That is the final piece of the puzzle for me.  
>>
>> Thanks so much.
>>
>> Aaron
>>
>> On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote:
>>>
>>> You need to transform your data dictionary so that the keys match the 
>>> models field names and then you can use:
>>>
>>> players_data = [{'number': 1, ...}, {...}]
>>>
>>> for data in players_data:
>>> Player.objects.bulk_create(**data)
>>>
>>> (or something similar with bulk_create())
>>>
>>>
>>> https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create
>>>
>>> On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg wrote:

 Hi everyone,

 I have several dictionaries that I would like to import into my django 
 project database, but I can't figure out exactly how.

 I have tried to implement through fixtures, through views and through 
 loaddata, but I must be doing something wrong at every turn- so if someone 
 could suggest a workflow, it would really help me a lot!

 My data is currently in a list of dictionaries called data:

 Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': 
 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 
 'university', 'number': 10, 'exp': 1},


 each dictionary within that list is a "player" who I'd like to input 
 his data into my model "Players"

 Enter code here...
 #models.py
 class Player(models.Model):

 number = models.CharField(max_length=2)
 player = models.CharField(max_length=50)
 position = models.CharField(max_length=2)
 height = models.CharField(max_length=50)
 weight = models.CharField(max_length=50)
 birth = models.DateField()
 exp = models.CharField(max_length=50)
 college = models.CharField(max_length=50)
 def __str__(self):
 return self.player


 There are about 500 players in that list of dictionaries above that I 
 would like to insert into this model.

 1) Can i run a function in the model above to insert the data into its 
 appropriate field?  If so, how do I execute that function?
 2) If it's a view that I need to execute-  do I just put the function 
 in views.py?  How then is the dictionary imported into the database?

 or... How would you go about getting that data into your database? 
  Please note that the data is coming from a url that might change from 
 time 
 to time.  But I think once i get the first iteration of data into these 
 models I can figure out how to update.  But the only way I can figure out 
 is to create them one by one in the shell or create a form and input them 
 one by one.

 If you have a solution, please share and be as detailed as possible 
 since I am a complete beginner with django.

 Peace and love,

 Aaron



-- 
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/7600ae91-ae54-4d33-9dab-83a0322194fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: MIDDLEWARE vs MIDDLEWARE_CLASSES: 'WSGIRequest' object has no attribute 'user'

2016-08-18 Thread Tim Graham
Are you running Django 1.10? It looks like your MIDDLEWARE setting is 
ignored which suggests you might be using an older version.

On Wednesday, August 17, 2016 at 6:43:14 PM UTC-4, Andrew Emory wrote:
>
> My settings.py file has the default MIDDLEWARE settings generated by 
> django-admin startapp:
>
> MIDDLEWARE = [
> 'django.middleware.security.SecurityMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.common.CommonMiddleware',
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> 'django.contrib.messages.middleware.MessageMiddleware',
> 'django.middleware.clickjacking.XFrameOptionsMiddleware',
> ]
>
> But when I visit /admin I get an Attribute Error with a traceback that 
> lists 
>
> Installed Middleware:
> ['django.middleware.common.CommonMiddleware',
>  'django.middleware.csrf.CsrfViewMiddleware']
>
> And Request_Information - Settings that lists: 
> MIDDLEWARE_CLASSES 
>
> ['django.middleware.common.CommonMiddleware',
>  'django.middleware.csrf.CsrfViewMiddleware']
>
>
> I am thinking of editing my settings file to read MIDDLEWARE_CLASSES 
> instead of MIDDLEWARE (because of stack-overflow articles) but according to 
> the Django Documentation that will only sweep the problem under the rug 
> rather than addressing the issue.  I don't see why, at this point, I should 
> deviate from the default settings.  Or, what caused the problem in the 
> first place.
>
> Any help would be appreciated.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+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/3eebfc50-1d50-41a0-93ba-c7a1a6ab8460%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models of Speedy Net

2016-08-18 Thread Avraham Serour
It doesn't matter, you should decide on something and stick to it,
consistency is more important than some suggestion you read somewhere.

What your suggested seems fair, write on your documentation that you
decided this and ask politely for contributions to follow this style

On Aug 18, 2016 3:08 PM, "Asad Jibran Ahmed"  wrote:

> The ordering of your attributes and methods inside the model class doesn't
> have to do with Django, it has to do with Python. Inside a class, the
> ordering doesn't matter as far as I understand. All of these documents you
> will find are thus just conventions to follow.
>
> You could come up with your own if you want, but it's usually a good idea
> to stick to something already out there are used by a lot of people, as it
> makes it easy for new comers to your code to quickly navigate the code.
> Since this is an open source project using the Django style guide you have
> linked to sounds like a good option.
>
> On Thursday, August 18, 2016 at 4:04:06 PM UTC+4, uri wrote:
>>
>> By the way, I found this document
>> 
>> and I changed the order of elements in our models accordingly. But what
>> about def __init__? And this document is for Django developers, what about
>> Django users? Is there another document for us?
>>
>> Thanks,
>> Uri.
>>
>>
>> *Uri Even-Chen*
>> [image: photo] Phone: +972-54-3995700
>> Email: u...@speedy.net
>> Website: http://www.speedysoftware.com/uri/en/
>> 
>> 
>> 
>> 
>>
>> On Thu, Aug 18, 2016 at 2:41 PM, Uri Even-Chen  wrote:
>>
>>> To django-users,
>>>
>>> We are developing Speedy Net, a new social networks with apps (Speedy
>>> Match and Speedy Composer). Speedy Net is using Django (the previous
>>> version is written in PHP). I would like to ask you about the models, in
>>> https://github.com/urievenchen/speedy-net/blob/master/
>>> speedy/net/accounts/models.py (it's an open source project; there are
>>> other models too), is the order of elements in the models correct?
>>> Currently the constants are first, then class Meta, then fields, then
>>> managers, then methods and properties (in arbitrary order). What is the
>>> common order of elements in Django projects? Does it matter at all? I read
>>> something about it in Django documentation, but I don't remember exactly
>>> where. I know the constants must be first in the model, before the fields,
>>> but what about class Meta? Any help will be appreciated.
>>>
>>> Thanks,
>>> Uri.
>>>
>>> *Uri Even-Chen*
>>> [image: photo] Phone: +972-54-3995700
>>> Email: u...@speedy.net
>>> Website: http://www.speedysoftware.com/uri/en/
>>> 
>>> 
>>> 
>>> 
>>>
>>
>> --
> 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/743db8ee-73d4-4f9e-96a1-7fea49aafecf%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/CAFWa6tL30SxzkMQn1mRCw2ErHe1T%3D_y%3DahfERmxfXeuju7160A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models of Speedy Net

2016-08-18 Thread Asad Jibran Ahmed
Sorry, I just checked and I'm wrong about the ordering of elements in a 
class. The reason the constants need to be first is because you are using 
them when defining your fields. But other than that, the order doesn't 
matter.

Here's the code that I used to check this:

def get_const():
print 'get_const()'
return 1

def make_list(i):
return [i]


class A(object):
attr = make_list(CONST)
CONST = get_const()


print A.attr

When I tried to execute it I got NameError: name 'CONST' is not defined. If 
you change the class definition so that the CONST declaration comes first, 
it works.


On Thursday, August 18, 2016 at 4:08:33 PM UTC+4, Asad Jibran Ahmed wrote:
>
> The ordering of your attributes and methods inside the model class doesn't 
> have to do with Django, it has to do with Python. Inside a class, the 
> ordering doesn't matter as far as I understand. All of these documents you 
> will find are thus just conventions to follow.
>
> You could come up with your own if you want, but it's usually a good idea 
> to stick to something already out there are used by a lot of people, as it 
> makes it easy for new comers to your code to quickly navigate the code. 
> Since this is an open source project using the Django style guide you have 
> linked to sounds like a good option.
>
> On Thursday, August 18, 2016 at 4:04:06 PM UTC+4, uri wrote:
>>
>> By the way, I found this document 
>> 
>>  
>> and I changed the order of elements in our models accordingly. But what 
>> about def __init__? And this document is for Django developers, what about 
>> Django users? Is there another document for us?
>>
>> Thanks,
>> Uri.
>>
>>
>> *Uri Even-Chen*   
>> [image: photo] Phone: +972-54-3995700
>> Email: u...@speedy.net
>> Website: http://www.speedysoftware.com/uri/en/
>>   
>>   
>>   
>> 
>>
>> On Thu, Aug 18, 2016 at 2:41 PM, Uri Even-Chen  wrote:
>>
>>> To django-users,
>>>
>>> We are developing Speedy Net, a new social networks with apps (Speedy 
>>> Match and Speedy Composer). Speedy Net is using Django (the previous 
>>> version is written in PHP). I would like to ask you about the models, in 
>>> https://github.com/urievenchen/speedy-net/blob/master/speedy/net/accounts/models.py
>>>  
>>> (it's an open source project; there are other models too), is the order of 
>>> elements in the models correct? Currently the constants are first, then 
>>> class Meta, then fields, then managers, then methods and properties (in 
>>> arbitrary order). What is the common order of elements in Django projects? 
>>> Does it matter at all? I read something about it in Django documentation, 
>>> but I don't remember exactly where. I know the constants must be first in 
>>> the model, before the fields, but what about class Meta? Any help will be 
>>> appreciated.
>>>
>>> Thanks,
>>> Uri.
>>>
>>> *Uri Even-Chen*   
>>> [image: photo] Phone: +972-54-3995700
>>> Email: u...@speedy.net
>>> Website: http://www.speedysoftware.com/uri/en/
>>>   
>>>   
>>>   
>>> 
>>>
>>
>>

-- 
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/96b45bfe-ff5f-4eae-a119-b0fa473a7c6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models of Speedy Net

2016-08-18 Thread Asad Jibran Ahmed
The ordering of your attributes and methods inside the model class doesn't 
have to do with Django, it has to do with Python. Inside a class, the 
ordering doesn't matter as far as I understand. All of these documents you 
will find are thus just conventions to follow.

You could come up with your own if you want, but it's usually a good idea 
to stick to something already out there are used by a lot of people, as it 
makes it easy for new comers to your code to quickly navigate the code. 
Since this is an open source project using the Django style guide you have 
linked to sounds like a good option.

On Thursday, August 18, 2016 at 4:04:06 PM UTC+4, uri wrote:
>
> By the way, I found this document 
> 
>  
> and I changed the order of elements in our models accordingly. But what 
> about def __init__? And this document is for Django developers, what about 
> Django users? Is there another document for us?
>
> Thanks,
> Uri.
>
>
> *Uri Even-Chen*   
> [image: photo] Phone: +972-54-3995700
> Email: u...@speedy.net 
> Website: http://www.speedysoftware.com/uri/en/
>   
>   
>   
>
> On Thu, Aug 18, 2016 at 2:41 PM, Uri Even-Chen  > wrote:
>
>> To django-users,
>>
>> We are developing Speedy Net, a new social networks with apps (Speedy 
>> Match and Speedy Composer). Speedy Net is using Django (the previous 
>> version is written in PHP). I would like to ask you about the models, in 
>> https://github.com/urievenchen/speedy-net/blob/master/speedy/net/accounts/models.py
>>  
>> (it's an open source project; there are other models too), is the order of 
>> elements in the models correct? Currently the constants are first, then 
>> class Meta, then fields, then managers, then methods and properties (in 
>> arbitrary order). What is the common order of elements in Django projects? 
>> Does it matter at all? I read something about it in Django documentation, 
>> but I don't remember exactly where. I know the constants must be first in 
>> the model, before the fields, but what about class Meta? Any help will be 
>> appreciated.
>>
>> Thanks,
>> Uri.
>>
>> *Uri Even-Chen*   
>> [image: photo] Phone: +972-54-3995700
>> Email: u...@speedy.net 
>> Website: http://www.speedysoftware.com/uri/en/
>>   
>>   
>>   
>> 
>>
>
>

-- 
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/743db8ee-73d4-4f9e-96a1-7fea49aafecf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Models of Speedy Net

2016-08-18 Thread Uri Even-Chen
By the way, I found this document

and I changed the order of elements in our models accordingly. But what
about def __init__? And this document is for Django developers, what about
Django users? Is there another document for us?

Thanks,
Uri.


*Uri Even-Chen*
[image: photo] Phone: +972-54-3995700
Email: u...@speedy.net
Website: http://www.speedysoftware.com/uri/en/
  
    

On Thu, Aug 18, 2016 at 2:41 PM, Uri Even-Chen  wrote:

> To django-users,
>
> We are developing Speedy Net, a new social networks with apps (Speedy
> Match and Speedy Composer). Speedy Net is using Django (the previous
> version is written in PHP). I would like to ask you about the models, in
> https://github.com/urievenchen/speedy-net/blob/master/speedy/net/accounts/
> models.py (it's an open source project; there are other models too), is
> the order of elements in the models correct? Currently the constants are
> first, then class Meta, then fields, then managers, then methods and
> properties (in arbitrary order). What is the common order of elements in
> Django projects? Does it matter at all? I read something about it in Django
> documentation, but I don't remember exactly where. I know the constants
> must be first in the model, before the fields, but what about class Meta?
> Any help will be appreciated.
>
> Thanks,
> Uri.
>
> *Uri Even-Chen*
> [image: photo] Phone: +972-54-3995700
> Email: u...@speedy.net
> Website: http://www.speedysoftware.com/uri/en/
> 
> 
>   
>

-- 
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/CAMQ2MsEhY-KV7JgxQmPm%2Brpz8iG0cCvYEV0Rn1eykCfkm-wb9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django on apache server

2016-08-18 Thread Asad Jibran Ahmed
Not being able to load CSS points to an Apache config issue. Did you setup 
apache so your static root configured to serve files from your static 
folder? Your apache config might be helpful here.

Also, what you have pasted here seems like a warning, so while you should 
fix it, this is probably not the cause of your CSS loading error.

On Thursday, August 18, 2016 at 3:44:14 PM UTC+4, hirok biswas wrote:
>
> while i have configuring django app on apchhe basically it works almost 
> well but shows this error log and css not work
> what can i do now???
> i am using 
> #apache2
> #django 1.9.6
> `
> [Wed Aug 17 14:54:12.747345 2016] [wsgi:error] [pid 17910:tid 
> 139970848413440] 
> /home/hirok/apachetest/venv/lib/python2.7/site-packages/django/template/utils.py:37:
>  
> RemovedInDjango110Warning: You haven't defined a TEMPLATES setting. You 
> must do so before upgrading to Django 1.10. Otherwise Django will be unable 
> to load templates.
> [Wed Aug 17 14:54:12.747414 2016] [wsgi:error] [pid 17910:tid 
> 139970848413440]   "unable to load templates.", RemovedInDjango110Warning)
> [Wed Aug 17 14:54:12.747423 2016] [wsgi:error] [pid 17910:tid 
> 139970848413440] 
> `
>

-- 
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/13c18a07-aedb-4560-b10b-bc21ac54de0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: manage or manage.py

2016-08-18 Thread ludovic coues
Who did you created this ?
Have you run `django-admin startproject mysite` ?

2016-08-18 10:41 GMT+02:00 Ziggo mail :
> Hi There
>
> I’m busy with starting with django.
>
> My first mysite shows me this:
>
> mysite/
>
> manage
>
> mysite/
>
> __pycache__
>
> __init__
>
> __init__.py-tpl
>
> Settings
>
> Settings.py-tpl
>
> Urls
>
> Urls.py-tpl
>
> Wsgi
>
> Wsqi.py-tpl
>
>
>
>
>
> Why is this differtent from your tutorial Writing your first Django app,
> part 1”?
>
>
>
> I installed python 3.5.1 and Django 1.10.
>
> Can you help me?
>
>
>
> Kind regards
>
> Joop
>
>
>
>
>
> --
> 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/01d1f92c%24439a06a0%24cace13e0%24%40ziggo.nl.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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/CAEuG%2BTajpRRwz9uQo2CJUg%2BoovLLHjXXh3EKwig_jSoatiUMDg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using hashids in django template

2016-08-18 Thread ludovic coues
You might be looking for this
https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/

2016-08-18 12:57 GMT+02:00 Paul Aswa :
> Is there means of encoding an id using hashids in django templates?
>
> --
> 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/fd7df219-a31a-408c-bbeb-ca0162492106%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
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/CAEuG%2BTY6tAbGC1fsvrAYizap-Zo-q_ZUrGk2yf7pMdNAqfkCnw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing django auth system with relational models

2016-08-18 Thread ludovic coues
No idea. I've never looked into model managers.
Maybe they can help in non-repeating code, maybe they won't work due
to the lack of access to the currently logged user.

2016-08-18 12:55 GMT+02:00 M Hashmi :
> Ludovic,
>
> Shouldn't she be using model managers for this?
>
> Just curious.
>
> Regards,
> Mudassar
>
>
>
>
>
>
> On Wed, Aug 17, 2016 at 2:37 PM, ludovic coues  wrote:
>>
>> Ok, sorry, I made a off by one error on the link :)
>>
>> Try that:
>>
>> # shops/admin.py
>> from django.contrib import admin
>> from products.models import Product
>> from .models import Shop
>>
>> class ShopAdmin(admin.ModelAdmin):
>> def formfield_for_manytomany(self, db_field, request, **kwargs):
>> if db_field.name == "product":
>> kwargs["queryset"] = Product.objects.filter(user=request.user)
>> return super(ShopAdmin,
>> self).formfield_for_manytomany(db_field, request, **kwargs)
>>
>> admin.site.register(Shop, ShopAdmin)
>>
>> ###
>>
>> It should give you the desired result
>>
>> 2016-08-17 19:31 GMT+02:00 Shamaila Moazzam :
>> >
>> > shops/admin.py
>> > from .models import Shop
>> >
>> > admin.site.register(Shop)
>> >
>> >
>> > products/admin.py
>> >
>> >
>> > from .models import Product, Variation, ProductImage, Category,
>> > ProductFeatured, color_product, size_product
>> >
>> >
>> >
>> > class ProductImageInline(admin.TabularInline):
>> > model = ProductImage
>> > extra = 0
>> > max_num = 10
>> >
>> > class VariationInline(admin.TabularInline):
>> > model = Variation
>> > extra = 0
>> > max_num = 10
>> >
>> >
>> > class ProductAdmin(admin.ModelAdmin):
>> > list_display = ['__unicode__', 'price',]
>> > inlines = [
>> > ProductImageInline,
>> > VariationInline,
>> >
>> >
>> > ]
>> > class Meta:
>> > model = Product
>> >
>> >
>> > admin.site.register(Product, ProductAdmin)
>> >
>> >
>> >
>> >
>> > #admin.site.register(Variation)
>> >
>> > admin.site.register(ProductImage)
>> >
>> >
>> > admin.site.register(Category)
>> >
>> >
>> > admin.site.register(ProductFeatured)
>> >
>> > admin.site.register(color_product)
>> >
>> > admin.site.register(size_product)
>> >
>> > On Wednesday, August 17, 2016 at 9:23:31 PM UTC+5, ludovic coues wrote:
>> >>
>> >> Could you share your admin.py file ?
>> >>
>> >> You might be interested into this part of the documentation:
>> >>
>> >>
>> >> https://docs.djangoproject.com/en/1.10/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_foreignkey
>> >>
>> >> 2016-08-17 17:20 GMT+02:00 Shamaila Moazzam :
>> >> > @Ludovic there is no error. Just I don't want to get all the products
>> >> > pre-populated. I need empty products field and only when user uploads
>> >> > products then it should show me products. Please advise
>> >> >
>> >> > On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam
>> >> > wrote:
>> >> >>
>> >> >> Hi,
>> >> >>
>> >> >> I am a beginner and please forgive me if my question is not up to
>> >> >> the
>> >> >> standard. I've got two models one is Product which is saved in db
>> >> >> already
>> >> >> and another one is Shop. I am trying to related both models with
>> >> >> following
>> >> >> code.
>> >> >>
>> >> >> class Product(models.Model):
>> >> >> user = models.ForeignKey(settings.USER_AUTH_MODEL)
>> >> >> title = models.CharField(max_length=120)
>> >> >> description = models.TextField(blank=True, null=True)
>> >> >> price = models.DecimalField(decimal_places=2, max_digits=20)
>> >> >> publish_date = models.DateTimeField(auto_now=False,
>> >> >> auto_now_add=False, null=True, blank= True)
>> >> >> expire_date = models.DateTimeField(auto_now=False,
>> >> >> auto_now_add=False,
>> >> >> null=True, blank=True)
>> >> >> active = models.BooleanField(default=True)
>> >> >> categories = models.ManyToManyField('Category', blank=True)
>> >> >> default = models.ForeignKey('Category',
>> >> >> related_name='default_category', null=True, blank=True)
>> >> >> hitcounts = GenericRelation(HitCount,
>> >> >> content_type_field='content_type', object_id_field='object_pk',)
>> >> >>
>> >> >>
>> >> >> objects = ProductManager()
>> >> >>
>> >> >>
>> >> >> class Meta:
>> >> >> ordering = ["-title"]
>> >> >>
>> >> >>
>> >> >> def __unicode__(self):
>> >> >> return self.title
>> >> >>
>> >> >>
>> >> >> class Shop(models.Model):
>> >> >> product = models.ManyToManyField(Product)
>> >> >>
>> >> >> title = models.CharField(max_length=120, null=False)
>> >> >> image = models.ImageField(upload_to=image_upload_to_shop,
>> >> >> null=True)
>> >> >> location = models.CharField(max_length=120)
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> def __unicode__(self):
>> >> >> return str(self.title)
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> With above I've got it added in my admin.py for Shop app and now I
>> >> >> have
>> >> >> a
>> >> >> problem. When I add 

Using hashids in django template

2016-08-18 Thread Paul Aswa
Is there means of encoding an id using hashids 
 in django templates?

-- 
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/fd7df219-a31a-408c-bbeb-ca0162492106%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


manage or manage.py

2016-08-18 Thread Ziggo mail
Hi There 

I'm busy with starting with django.

My first mysite shows me this: 

mysite/

manage

mysite/

__pycache__

__init__

__init__.py-tpl

Settings

Settings.py-tpl

Urls

Urls.py-tpl

Wsgi

Wsqi.py-tpl

 

 

Why is this differtent from your tutorial Writing your first Django app,
part 1"?

 

I installed python 3.5.1 and Django 1.10.

Can you help me?

 

Kind regards

Joop

 

 

-- 
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/01d1f92c%24439a06a0%24cace13e0%24%40ziggo.nl.
For more options, visit https://groups.google.com/d/optout.


django on apache server

2016-08-18 Thread hirok biswas
while i have configuring django app on apchhe basically it works almost 
well but shows this error log and css not work
what can i do now???
i am using 
#apache2
#django 1.9.6
`
[Wed Aug 17 14:54:12.747345 2016] [wsgi:error] [pid 17910:tid 
139970848413440] 
/home/hirok/apachetest/venv/lib/python2.7/site-packages/django/template/utils.py:37:
 
RemovedInDjango110Warning: You haven't defined a TEMPLATES setting. You 
must do so before upgrading to Django 1.10. Otherwise Django will be unable 
to load templates.
[Wed Aug 17 14:54:12.747414 2016] [wsgi:error] [pid 17910:tid 
139970848413440]   "unable to load templates.", RemovedInDjango110Warning)
[Wed Aug 17 14:54:12.747423 2016] [wsgi:error] [pid 17910:tid 
139970848413440] 
`

-- 
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/c7fca004-2847-4e5e-b7f1-501a54f838c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Models of Speedy Net

2016-08-18 Thread Uri Even-Chen
To django-users,

We are developing Speedy Net, a new social networks with apps (Speedy Match
and Speedy Composer). Speedy Net is using Django (the previous version is
written in PHP). I would like to ask you about the models, in
https://github.com/urievenchen/speedy-net/blob/master/speedy/net/accounts/models.py
(it's an open source project; there are other models too), is the order of
elements in the models correct? Currently the constants are first, then
class Meta, then fields, then managers, then methods and properties (in
arbitrary order). What is the common order of elements in Django projects?
Does it matter at all? I read something about it in Django documentation,
but I don't remember exactly where. I know the constants must be first in
the model, before the fields, but what about class Meta? Any help will be
appreciated.

Thanks,
Uri.

*Uri Even-Chen*
[image: photo] Phone: +972-54-3995700
Email: u...@speedy.net
Website: http://www.speedysoftware.com/uri/en/
  
    

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


Re: Implementing django auth system with relational models

2016-08-18 Thread M Hashmi
Ludovic,

Shouldn't she be using model managers for this?

Just curious.

Regards,
Mudassar






On Wed, Aug 17, 2016 at 2:37 PM, ludovic coues  wrote:

> Ok, sorry, I made a off by one error on the link :)
>
> Try that:
>
> # shops/admin.py
> from django.contrib import admin
> from products.models import Product
> from .models import Shop
>
> class ShopAdmin(admin.ModelAdmin):
> def formfield_for_manytomany(self, db_field, request, **kwargs):
> if db_field.name == "product":
> kwargs["queryset"] = Product.objects.filter(user=request.user)
> return super(ShopAdmin,
> self).formfield_for_manytomany(db_field, request, **kwargs)
>
> admin.site.register(Shop, ShopAdmin)
>
> ###
>
> It should give you the desired result
>
> 2016-08-17 19:31 GMT+02:00 Shamaila Moazzam :
> >
> > shops/admin.py
> > from .models import Shop
> >
> > admin.site.register(Shop)
> >
> >
> > products/admin.py
> >
> >
> > from .models import Product, Variation, ProductImage, Category,
> > ProductFeatured, color_product, size_product
> >
> >
> >
> > class ProductImageInline(admin.TabularInline):
> > model = ProductImage
> > extra = 0
> > max_num = 10
> >
> > class VariationInline(admin.TabularInline):
> > model = Variation
> > extra = 0
> > max_num = 10
> >
> >
> > class ProductAdmin(admin.ModelAdmin):
> > list_display = ['__unicode__', 'price',]
> > inlines = [
> > ProductImageInline,
> > VariationInline,
> >
> >
> > ]
> > class Meta:
> > model = Product
> >
> >
> > admin.site.register(Product, ProductAdmin)
> >
> >
> >
> >
> > #admin.site.register(Variation)
> >
> > admin.site.register(ProductImage)
> >
> >
> > admin.site.register(Category)
> >
> >
> > admin.site.register(ProductFeatured)
> >
> > admin.site.register(color_product)
> >
> > admin.site.register(size_product)
> >
> > On Wednesday, August 17, 2016 at 9:23:31 PM UTC+5, ludovic coues wrote:
> >>
> >> Could you share your admin.py file ?
> >>
> >> You might be interested into this part of the documentation:
> >>
> >> https://docs.djangoproject.com/en/1.10/ref/contrib/admin/
> #django.contrib.admin.ModelAdmin.formfield_for_foreignkey
> >>
> >> 2016-08-17 17:20 GMT+02:00 Shamaila Moazzam :
> >> > @Ludovic there is no error. Just I don't want to get all the products
> >> > pre-populated. I need empty products field and only when user uploads
> >> > products then it should show me products. Please advise
> >> >
> >> > On Wednesday, August 17, 2016 at 6:37:51 PM UTC+5, Shamaila Moazzam
> >> > wrote:
> >> >>
> >> >> Hi,
> >> >>
> >> >> I am a beginner and please forgive me if my question is not up to the
> >> >> standard. I've got two models one is Product which is saved in db
> >> >> already
> >> >> and another one is Shop. I am trying to related both models with
> >> >> following
> >> >> code.
> >> >>
> >> >> class Product(models.Model):
> >> >> user = models.ForeignKey(settings.USER_AUTH_MODEL)
> >> >> title = models.CharField(max_length=120)
> >> >> description = models.TextField(blank=True, null=True)
> >> >> price = models.DecimalField(decimal_places=2, max_digits=20)
> >> >> publish_date = models.DateTimeField(auto_now=False,
> >> >> auto_now_add=False, null=True, blank= True)
> >> >> expire_date = models.DateTimeField(auto_now=False,
> >> >> auto_now_add=False,
> >> >> null=True, blank=True)
> >> >> active = models.BooleanField(default=True)
> >> >> categories = models.ManyToManyField('Category', blank=True)
> >> >> default = models.ForeignKey('Category',
> >> >> related_name='default_category', null=True, blank=True)
> >> >> hitcounts = GenericRelation(HitCount,
> >> >> content_type_field='content_type', object_id_field='object_pk',)
> >> >>
> >> >>
> >> >> objects = ProductManager()
> >> >>
> >> >>
> >> >> class Meta:
> >> >> ordering = ["-title"]
> >> >>
> >> >>
> >> >> def __unicode__(self):
> >> >> return self.title
> >> >>
> >> >>
> >> >> class Shop(models.Model):
> >> >> product = models.ManyToManyField(Product)
> >> >>
> >> >> title = models.CharField(max_length=120, null=False)
> >> >> image = models.ImageField(upload_to=image_upload_to_shop,
> >> >> null=True)
> >> >> location = models.CharField(max_length=120)
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> def __unicode__(self):
> >> >> return str(self.title)
> >> >>
> >> >>
> >> >>
> >> >>
> >> >> With above I've got it added in my admin.py for Shop app and now I
> have
> >> >> a
> >> >> problem. When I add a shop it shows all the past products
> prepopulated
> >> >> in my
> >> >> "products" field.
> >> >> I just need to add the products that shop account holder has
> uploaded.
> >> >> I
> >> >> wish to use django\s built-in auth model to register shop holders.
> >> >> Again the
> >> >> confusion is that where should I add
> >> >> USER_AUTH_MODEL in "Shop" or in "Products". If I added it shop app
> then
> >> >> for beginner 

Re: connecting to mssql database

2016-08-18 Thread sum abiut
got it fixed, it was the version issue. i down grade from django 1.10 to
1.9.9 and it fixed.

cheers

On Thu, Aug 18, 2016 at 9:18 AM, sum abiut  wrote:

> now i have made changes to settings file
>
> DATABASES = {
> 'default': {
> 'ENGINE': 'django_pyodbc',
> 'NAME': xxx',
> 'USER': 'xx',
> 'PASSWORD': 'xx',
> 'HOST': 'xxx',
> 'PORT': '1433',
>
> 'OPTIONS': {
> 'host_is_server': True,
> }
> }
> }
>
>
>
> and i am getting the error :
> File 
> "/var/www/mssqlconnect/local/lib/python2.7/site-packages/django_pyodbc/base.py",
> line 96, in 
> raise ImproperlyConfigured("Django %d.%d is not supported." %
> DjangoVersion[:2])
> django.core.exceptions.ImproperlyConfigured: Django 1.10 is not supported.
>
>
> is this something has to do with version issue?
>
> cheers
>
>
>
>
> On Thu, Aug 18, 2016 at 8:44 AM, sum abiut  wrote:
>
>> I am getting the error mes
>>
>> django.db.utils.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data
>> source name not found, and no default driver specified (0)
>> (SQLDriverConnect)')sage
>>
>>
>>
>>
>> On Wed, Aug 17, 2016 at 11:17 PM, Daniel França 
>> wrote:
>>
>>> What errors are you getting?
>>>
>>> On Wed, 17 Aug 2016 at 14:15 sum abiut  wrote:
>>>

 Hi,
 i am having a very hard time figuring out how to connect to a mssql
 database. i've try following this guide but nothing seems to be working.
 please help

 http://www.tivix.com/blog/getting-django-working-with-mssql-pyodbc/

 https://pypi.python.org/pypi/django-pyodbc-azure

 cheers,

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To post to this group, send email to django-users@googlegroups.com.
 Visit this group at https://groups.google.com/group/django-users.
 To view this discussion on the web visit https://groups.google.com/d/ms
 gid/django-users/CAPCf-y5M37%2B9JRspvMEtUUOZVOp1SaUSuToGs0Vd
 H%2B_DydPC8A%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/ms
>>> gid/django-users/CACPst9LGPZTHHcKDB0EVUpgrEdrBzTtMFxeCib4WSc
>>> SEqWf5Mg%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/CAPCf-y7yu_V6m1QzNUxHu12pCJbnNVURBvy3%2B1mQ8ezDq5VXQA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django query not returning all objects

2016-08-18 Thread Todor Velichkov
Another solution would be to annotate min/max deadline date and order by 
the annotation. Something like:

cases = HeartFlowCase.objects.all().annotate(min_deadline=Min(
'data__deadline')).order_by('min_deadline')


On Thursday, August 18, 2016 at 7:59:19 AM UTC+3, Constantine Covtushenko 
wrote:
>
> Hi Koonal,
>
> As said in django doc 
>  you 
> can use `distinct()` to remove duplicated rows from first query.
>
> I believe with this your pagination should works as expected.
>
> Regards,
>
>
> On Thu, Aug 18, 2016 at 2:58 AM, Koonal Bharadwaj  > wrote:
>
>> Hello,
>>
>> The issue:
>>
>> When trying to order_by on a related model duplicate entries are created. 
>> I solved this with an OrderedSet that is applied after paginating (
>> http://code.activestate.com/recipes/576694/). However, when I try to 
>> paginate the queryset, all the results are not returned. It's missing a few 
>> table rows. 
>>
>> Models:
>>
>> class HeartFlowCase(models.Model):
>> """
>>  
>> A Hearflow Case.
>>  
>> This serves at the true state of a case as it is processed through the 
>> system.
>> It also holds the results of each step of the processing.
>>
>> """
>>
>> # Primary
>> hf_id = models.CharField('HeartFlow ID', max_length=200, blank=True, 
>> unique=True)
>> canonical_data = models.ForeignKey('cases.CaseData', to_field='uuid', 
>> related_name="canonical_data")
>>
>>
>> class CaseData(models.Model):
>> """
>> Extracted and computed values related to a single processing run of a 
>> case.
>>
>> A HeartFlowCase can have multiple runs associated with it.
>> The one which is accepted to be the "clinically accurate" one is the one 
>> referred to as 'canonical_data' by
>> the HeartFlowCase itself.
>>
>> """
>>
>> # Primary
>> heartflowcase = models.ForeignKey(HeartFlowCase, related_name='data', 
>> blank=True, null=True)
>> uuid = models.CharField('Case Data UUID', max_length=200, blank=False, 
>> null=False, unique=True)
>> deadline = models.DateTimeField('Deadline', blank=True, 
>> default=get_default_deadline)
>>
>>
>> As you can see, there is a ForeignKey to canonical CaseData from 
>> HeartFlowCase and a ForeignKey to HeartFlowCase from CaseData. So you 
>> can have multiple CaseDatas per HeartFlowCase. 
>>
>> Structure:
>>
>> HeartFlowCase
>> |
>> data - CaseData1
>> \
>>  \ CaseData2
>>
>>
>> For example: 
>>
>> Total number of HeartFlow objects are 5 with 2 CaseDatas each. If I 
>> order_by deadline on CaseData as: 
>> cases = HeartFlowCase.objects.all().order_by(data__deadline)
>> this returns duplicates since there are multiple CaseDatas, which is 
>> fine. Now I try and paginate it by applying:
>>
>> paginator = Paginator(cases, 2)
>> cases = paginator.page(1)
>>
>> Now the SQL query has a LIMIT and OFFSET given. If the order_by gives 
>> duplicate HeartFlowCase objects this hits the LIMIT number and the results 
>> that are returned are missing a HeartFlowCase object. So if 2 duplicates are 
>> returned per case after applying the OrderedSet I get only one case back and 
>> missing one case since it was never returned from the database. As I goto 
>> the next page:
>>
>> cases = paginator.page(2)
>>
>> that missingHeartFlowCase object that was not returned from the first page 
>> queryset is lost forever and is never displayed. 
>>
>>
>> I hope this is clear. Please let me know if I can clarify further. Any help 
>> would greatly be appreciated. Thanks.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/61ec03f6-3325-49fe-bcdc-a7ca50784dc0%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/61031ac3-18df-43aa-9dc3-08be411863ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Python dictionaries saved to models

2016-08-18 Thread Todor Velichkov
Maybe a data migration 
 
is what you are looking for.

On Thursday, August 18, 2016 at 8:38:33 AM UTC+3, Aaron Weisberg wrote:
>
> Great- thanks Tim.
>
> I understand the Python, but what I guess where I'm fuzzy is where to 
> exactly put that code.  
>
> Do I put it in the models.py? class.py?  and how do I execute?
>
> That is the final piece of the puzzle for me.  
>
> Thanks so much.
>
> Aaron
>
> On Wednesday, August 17, 2016 at 3:48:18 PM UTC-5, Tim Graham wrote:
>>
>> You need to transform your data dictionary so that the keys match the 
>> models field names and then you can use:
>>
>> players_data = [{'number': 1, ...}, {...}]
>>
>> for data in players_data:
>> Player.objects.bulk_create(**data)
>>
>> (or something similar with bulk_create())
>>
>> https://docs.djangoproject.com/en/stable/ref/models/querysets/#bulk-create
>>
>> On Wednesday, August 17, 2016 at 1:42:04 PM UTC-4, Aaron Weisberg wrote:
>>>
>>> Hi everyone,
>>>
>>> I have several dictionaries that I would like to import into my django 
>>> project database, but I can't figure out exactly how.
>>>
>>> I have tried to implement through fixtures, through views and through 
>>> loaddata, but I must be doing something wrong at every turn- so if someone 
>>> could suggest a workflow, it would really help me a lot!
>>>
>>> My data is currently in a list of dictionaries called data:
>>>
>>> Enter code here...data = [{'pos': 'position', 'player': 'name', 'ht': 
>>> 'height', 'wt': 175, 'birth': 'September 9, 1967', 'college': 
>>> 'university', 'number': 10, 'exp': 1},
>>>
>>>
>>> each dictionary within that list is a "player" who I'd like to input his 
>>> data into my model "Players"
>>>
>>> Enter code here...
>>> #models.py
>>> class Player(models.Model):
>>>
>>> number = models.CharField(max_length=2)
>>> player = models.CharField(max_length=50)
>>> position = models.CharField(max_length=2)
>>> height = models.CharField(max_length=50)
>>> weight = models.CharField(max_length=50)
>>> birth = models.DateField()
>>> exp = models.CharField(max_length=50)
>>> college = models.CharField(max_length=50)
>>> def __str__(self):
>>> return self.player
>>>
>>>
>>> There are about 500 players in that list of dictionaries above that I 
>>> would like to insert into this model.
>>>
>>> 1) Can i run a function in the model above to insert the data into its 
>>> appropriate field?  If so, how do I execute that function?
>>> 2) If it's a view that I need to execute-  do I just put the function in 
>>> views.py?  How then is the dictionary imported into the database?
>>>
>>> or... How would you go about getting that data into your database? 
>>>  Please note that the data is coming from a url that might change from time 
>>> to time.  But I think once i get the first iteration of data into these 
>>> models I can figure out how to update.  But the only way I can figure out 
>>> is to create them one by one in the shell or create a form and input them 
>>> one by one.
>>>
>>> If you have a solution, please share and be as detailed as possible 
>>> since I am a complete beginner with django.
>>>
>>> Peace and love,
>>>
>>> Aaron
>>>
>>>

-- 
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/2fa36523-26d0-4a2a-9428-b4a5fa88fda1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.