Re: how to set up a calculated field in Django?

2019-10-22 Thread nm
One way I can think of is to add a property 
 to your model. 
I believe something like this should work:

```
## in your model class:
mother_alive = models.IntegerField(choices=YES_NO_CHOICES, blank=True, 
null=True, default=1)
father_alive = models.IntegerField(choices=YES_NO_CHOICES, blank=True, 
null=True, default=1)

@property
def is_orphan(self):
return self.mother_alive == 0 and self.father_alive == 0  # not 
sure what the "no" value is, you have to set it appropriately
```
You'll then be able to access it as an attribute of the model:
```
Child.objects.get(id=1).is_orphan
# True or False
```

This value will not be stored in the database, though, and you won't be 
able to filter children by the `is_orphan` column, because there'll be no 
such column.

Another approach would be to use annotations 
.
 
With annotations, you can do aggregations, just like with any other model 
field.


On Monday, 21 October 2019 20:05:04 UTC+2, Eileen Bauer wrote:
>
> Hi,
> i have the following items in my model:
> mother_alive = models.IntegerField(choices=YES_NO_CHOICES, blank=True, 
> null=True, default=1)
> father_alive = models.IntegerField(choices=YES_NO_CHOICES, blank=True, 
> null=True, default=1)
>
> and I'd like to set up a generated field for them so I'd be able to detect 
> whether the child is an orphan or not. In MySQL i believe it'd look like 
> this:
> orphan varchar(101) GENERATED ALWAYS AS (mother_alive+father_alive) 
> VIRTUAL,
>
> I don't know how to change my model to do that...
>
> Any help?
>
> -Eileen
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cd4aed5d-223b-4c9a-9678-aa0fd5b9464f%40googlegroups.com.


Re: Django sockets

2019-08-28 Thread nm

Perhaps you're looking for Django Channels? 


On Tuesday, 27 August 2019 15:08:47 UTC+2, Suraj Thapa FC wrote:
>
> Anyone know making chat app using sockets in rest api
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9a45875f-a538-4489-a486-4ccdb3be71ab%40googlegroups.com.


Re: Write urls without regex in DRF

2019-05-23 Thread nm
Yes, it's possible to write this code without using regexp, and it should 
work the same.

If you have a look at the source code of the routers, there's a method 
`get_urls` in SimpleRouter (you can find it here 
https://github.com/encode/django-rest-framework/blob/master/rest_framework/routers.py),
 
which, among others, does:

regex = route.url.format(
prefix=prefix,
lookup=lookup,
trailing_slash=self.trailing_slash
)


where `route.url` is something like 

url=r'^{prefix}/{lookup}{trailing_slash}$',


and `prefix` is the first argument you pass to `router.register` - in your 
case, an empty string:

def register(self, prefix, viewset, basename=None, base_name=None)


It does not seem to matter whether you put `prefix=r''` or `prefix=''`, the 
ultimate url regex looks the same.
Disclaimer: I assume you're using the latest version of DRF (3.9.x); I 
haven checked how the code looks in older versions. 

On Wednesday, 22 May 2019 17:20:20 UTC+2, Rounak Jain wrote:

>
> I am using DRF Viewsets to auto-generate URLs for different views. Is it 
> possible to write the code below without using regex?
> Thanks
>
> from .views import TaskViewSet
> from rest_framework.routers import DefaultRouter
>
> router = DefaultRouter()
> router.register(r'', TaskViewSet, basename='task')
> urlpatterns = router.urls
>
>
>
>
>

-- 
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/e929c4c9-a174-434d-bda9-9000e5cf8892%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Website slowed down drasticaly

2019-05-02 Thread nm
Django Debug Toolbar is a useful tool, it'll tell you what takes the 
biggest amount of time while the website loads. 

One caveat regarding performance: I once developed a project (running 
Django 1.8 and Python 3.4), and the Toolbar slowed down our back end 
tremendously. We tried to figure out the reason why some pages took as much 
as 20 seconds to load, and discovered by chance that if you disabled the 
toolbar, performance improved considerably (down to 3-4 seconds, or so). 
Obviously, you don't use it in production, so it's only an issue in 
development, but it may be worth knowing if you decide to use DDT. 

Granted, I'm not sure if this happens always, because it was the only 
project where I used DDT.

On Thursday, 2 May 2019 14:22:11 UTC+2, Chetan Ganji wrote:
>
> Not sure about whats the issue. You could do couple of things to 
> understand whats the root cause of the problem.
> I know they are generic guidelines. Anyone couldnt be more specific than 
> this.
>
>
>1. Benchmark the time required to process each request. You could 
>write a middleware to track this time. 
>Attach starttime to each request object and read that at the time of 
>returning the response. 
>
>2. Try using the django debug toolbar to see how much time it is 
>taking to execute the sql queries. 
>There might be some room for improvement as most developers dont 
>practice sql regularly. 
>https://django-debug-toolbar.readthedocs.io/en/latest/
>
>3. Maybe try using a different database - PostgreSQL, MySQL, etc.
>
>4. But if you have time for R, you could try using the different 
>python implementation, it is said to be faster in many cases than cpython. 
>It's not 100% compliant i.e. some packages might not work with pypy. 
>So please do your research before walking down this road.
>https://pypy.org/
>
>5. Try using a different web server. If you are using Apache, try 
>using nginx. Also use a different wsgi server. If you are using gunicorn, 
>try with waitress or others. 
>
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji...@gmail.com 
> http://ryucoder.in
>
>
> On Thu, May 2, 2019 at 5:09 PM Saurabh Adhikary  > wrote:
>
>> Hello , 
>>
>> I'm using Django version 1.8.1  and Python version 2.7.12 . Suddenly 
>> since Feb '19 there has been a drastic decrease in my website's response 
>> rate.
>> For sure , there has been some minor increase in the no of hits, but the 
>> performance is too bad.
>>
>> Initially , the thought came that the hardware of the server was old , so 
>> a new server with high configuration was bought.
>> We have done the new indexing also on it.
>> Still the sought for a higher performance is awaited.
>>
>>
>> Is it that the Django support for 1.8.1 or Python support for 2.7.12 has 
>> reduced and that is casing the website to slow down or I am missing out on 
>> something ?
>> Kindly help. 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@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/238a6da2-8f34-4b8b-939c-e20d4306545b%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/9aa4a7dc-4e6c-4de4-a20c-c9eb4b6e7ef3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Step-by-Step Machine Learning with Python [Full Packt Paid Video Course for free]

2019-04-16 Thread nm
Yesterday I received an invitation to a google group from the same user, as 
well as two emails with links to purportedly educational videos (I haven't 
opened those links though). The entire list of recipients was visible, and 
I got pretty pissed that my email was there too.

On Tuesday, 16 April 2019 13:21:21 UTC+2, Milind Thombre wrote:
>
> Beware: This opened a popup and I got a warning from my AV s/w.
>
> Admin: Kindly bump this user off the forum. Also, if others observe a 
> similar behaviour of the link, kindly report this guy to the FBI.
>
> On Mon, Apr 15, 2019 at 11:59 PM Zahid Hossain  > wrote:
>
>> please subscribe o get more paid course for free 
>> https://youtu.be/-Za8_t2DBeU
>>
>> -- 
>> 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...@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/8b8706d4-41d5-4c51-9a67-a73e3068b3a9%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/5031e556-320f-43dc-ae33-33ab2be314f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Complex query on inner join - case for __ne?

2019-04-15 Thread nm
I've only had a quick look at your problem, but looks like maybe this 
section of the Django documentation could be useful: 
https://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships


On Friday, 12 April 2019 15:10:59 UTC+2, Michael Thomas wrote:
>
> Hello everyone,
>
> I've run into what I believe is a limitation of the ORM that other people 
> must be dealing with somehow, but I can't seem to figure out a sensible 
> solution.
>
> I think it's easiest to describe the problem with code.
>
> For the following models:
>
> class Foo(models.Model):
> name = models.CharField(max_length=64)
>
>
> class Bar(models.Model):
> foo = models.ForeignKey(Foo, on_delete=models.CASCADE)
> attribute_1 = models.IntegerField()
> attribute_2 = models.IntegerField()
>
> I want to select all Foo() that have 1 or more bar with attribute_1 not 
> equal to 1, and attribute_2 equal to 2.
>
> Eg. SQL something like this:
>
> SELECT 
> "app_foo"."id", 
> "app_foo"."name" 
> FROM "app_foo" 
> INNER JOIN "app_bar" ON (
> "app_foo"."id" = "app_bar"."foo_id"
> ) 
> WHERE (
> "app_bar"."attribute_1" <> 1 
> AND "app_bar"."attribute_2" = 2
> )
>
> However, here's what I end up with...
>
>
> print(Foo.objects.exclude(bar__attribute_1=1).filter(bar__attribute_2=2).query)
> SELECT 
> "app_foo"."id", 
> "app_foo"."name" 
> FROM "app_foo" 
> INNER JOIN "app_bar" ON (
> "app_foo"."id" = "app_bar"."foo_id"
> ) 
> WHERE (
> NOT (
> "app_foo"."id" IN (
> SELECT 
> U1."foo_id" 
> FROM "app_bar" U1 
> WHERE U1."attribute_1" = 1
> )
> ) 
> AND "app_bar"."attribute_2" = 2
> )
>
> print(Foo.objects.filter(~Q(bar__attribute_1=1), bar__attribute_2=2).query)
> Exact same SQL output as above 
>
> Interestingly enough, a simple query for attribute_1=1 and attribute_2=2 
> works as expected, so it would be trivial to do this with a __ne operator 
> (if it existed), without any other changes to the ORM:
>
> print(Foo.objects.filter(bar__attribute_1=1, bar__attribute_2=2).query)
> SELECT 
> "app_foo"."id", 
> "app_foo"."name" 
> FROM "app_foo" 
> INNER JOIN "app_bar" ON (
> "app_foo"."id" = "app_bar"."foo_id"
> ) 
> WHERE (
> "app_bar"."attribute_1" = 1 
> AND "app_bar"."attribute_2" = 2
> )
>
> Am I missing something here? How are other people tackling this?
>
> Kind Regards,
> Michael Thomas
>
>

-- 
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/8142abe8-1d14-4eff-aa6b-0f281ce14181%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: upgrading the pip version in dockerized django container

2019-04-10 Thread nm

Try `exec` instead of `run`. `run` runs the command in a new container, so 
each time you perform `docker-compose run web `, a new copy of the 
container is created. See the documentation: 
https://docs.docker.com/compose/reference/run/

On Wednesday, 10 April 2019 11:56:53 UTC+2, Shubham Joshi wrote:
>
> I am trying to upgrade pip version in docker
>
>
> snj@snj-ThinkPad-T440p:~/school$ sudo docker-compose run web pip install 
> --upgrade pip
> Starting school_db_1 ... done
> Collecting pip
>   Downloading 
> https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl
>  
> (1.4MB)
> 100% || 1.4MB 62kB/s
> Installing collected packages: pip
>   Found existing installation: pip 9.0.1
> Uninstalling pip-9.0.1:
>   Successfully uninstalled pip-9.0.1
> Successfully installed pip-19.0.3
> snj@snj-ThinkPad-T440p:~/school$ sudo docker-compose run web pip --version
> Starting school_db_1 ... done
> pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
> snj@snj-ThinkPad-T440p:~/school$
>

-- 
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/ba933ef5-7178-4b54-925f-0ee42ad456c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: I Am A Begginer Web Developer - Need Help With Finding A Term

2019-04-02 Thread nm
Hi Rok, 
I suppose you want to *list* all your posts :) List is where you display 
many instances on one page (and your url is e.g. `.../classes/`). 
And as you probably already know, if you want to retrieve just one post (or 
class, or whatever you call it), you need a detail view, and the url will 
contain the retrieved item's pk (primary key): `.../classes/1`. 

Hope this is what you were looking for.


On Tuesday, 2 April 2019 03:22:59 UTC+2, Rok Klancar wrote:
>
> Hello developers!
>
> Much respect to you all.
>
> I have just finished a couple of hours browsing the web, but found no 
> solution. I guess my problem is simply *not knowing the right term *for 
> the thing that I am trying to make (in Django of course).
>
> Brief description:
> I have made a class 'Post' in *models.py *that represents four different 
> kind of data:
>
>- Date
>- Int
>- Text 1
>- Text 2
>
> It is sort of like a blog post. Now, in the official Django tutorial I 
> have learned how to make posts appear on separate pages.
> But I want the different instances of this class 'Post' appear one under 
> another on a single page (Today's post is on top, yesterday's is bellow the 
> today's, etc.).
>
> I hope I made my issue clear.
> I would be happy, just if you told me, how do you call this shape of a 
> page in Web Dev jargon.
>
> Have a nice day
> Rok
>
>

-- 
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/0604272b-068b-407f-8425-1a04ba82fecc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Must be my and and can't be my code -- tracing back a URL pattern type mismatch

2019-04-01 Thread nm
Then I'd suggest you try commenting out the relevant settings and urls 
(urlpatterns 
= [path('__debug__/', include(debug_toolbar.urls)),] or whatever you have 
there), and see what happens when you run `./manage.py check`. 

I once had a url-related problem that only appeared when I ran tests; it 
would disappear when I disabled the toolbar. Mine was a different one, but 
I thought maybe your error has something to do with the toolbar, since you 
said it certainly wasn't the app's code.

On Monday, 1 April 2019 15:51:18 UTC+2, Josh Marshall wrote:
>
> I do in fact use Django Debug Toolbar.
>
> On Mon, Apr 1, 2019 at 9:19 AM nm > 
> wrote:
>
>> Do you use any additional packages like e.g. Django Debug Toolbar? Or 
>> anything else that could mess with your urls? This is just a wild guess, 
>> but since nobody has answered with a better idea yet... 
>>
>> On Sunday, 31 March 2019 04:31:42 UTC+2, Josh Marshall wrote:
>>>
>>> I'm helping out on a project, but am running into a paradox of a bug 
>>> must existing in the code, but no project code is called.  Not sure how to 
>>> deal with this one.  It looks related to URL setup and the urls.py file is 
>>> practically identical to the examples.  Can anyone make sense of this stack 
>>> trace?
>>>
>>>
>>> ```
>>> [anadon@goodadvicemallard project1]$ poetry run ./manage.py check
>>> /home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/psycopg2/__init__.py:144:
>>>  
>>> UserWarning: The psycopg2 wheel package will be renamed from release 2.8; 
>>> in order to keep installing from binary please use "pip install 
>>> psycopg2-binary" instead. For details see: <
>>> http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
>>>   """)
>>> Auto generated 7 views for endpoints
>>> Traceback (most recent call last):
>>>   File "./manage.py", line 28, in 
>>> execute_from_command_line(sys.argv)
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>>>  
>>> line 381, in execute_from_command_line
>>> utility.execute()
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>>>  
>>> line 375, in execute
>>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/base.py",
>>>  
>>> line 316, in run_from_argv
>>> self.execute(*args, **cmd_options)
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/base.py",
>>>  
>>> line 353, in execute
>>> output = self.handle(*args, **options)
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/commands/check.py",
>>>  
>>> line 65, in handle
>>> fail_level=getattr(checks, options['fail_level']),
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/base.py",
>>>  
>>> line 379, in check
>>> include_deployment_checks=include_deployment_checks,
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/base.py",
>>>  
>>> line 366, in _run_checks
>>> return checks.run_checks(**kwargs)
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/checks/registry.py",
>>>  
>>> line 71, in run_checks
>>> new_errors = check(app_configs=app_configs)
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/checks/urls.py",
>>>  
>>> line 13, in check_url_config
>>> return check_resolver(resolver)
>>>   File 
>>> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/checks/urls.py",
>>>  
>>> line 23, in check_resolver
>>> re

Re: Must be my and and can't be my code -- tracing back a URL pattern type mismatch

2019-04-01 Thread nm
Do you use any additional packages like e.g. Django Debug Toolbar? Or 
anything else that could mess with your urls? This is just a wild guess, 
but since nobody has answered with a better idea yet... 

On Sunday, 31 March 2019 04:31:42 UTC+2, Josh Marshall wrote:
>
> I'm helping out on a project, but am running into a paradox of a bug must 
> existing in the code, but no project code is called.  Not sure how to deal 
> with this one.  It looks related to URL setup and the urls.py file is 
> practically identical to the examples.  Can anyone make sense of this stack 
> trace?
>
>
> ```
> [anadon@goodadvicemallard project1]$ poetry run ./manage.py check
> /home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/psycopg2/__init__.py:144:
>  
> UserWarning: The psycopg2 wheel package will be renamed from release 2.8; 
> in order to keep installing from binary please use "pip install 
> psycopg2-binary" instead. For details see: <
> http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
>   """)
> Auto generated 7 views for endpoints
> Traceback (most recent call last):
>   File "./manage.py", line 28, in 
> execute_from_command_line(sys.argv)
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>  
> line 381, in execute_from_command_line
> utility.execute()
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/__init__.py",
>  
> line 375, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/base.py",
>  
> line 316, in run_from_argv
> self.execute(*args, **cmd_options)
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/base.py",
>  
> line 353, in execute
> output = self.handle(*args, **options)
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/commands/check.py",
>  
> line 65, in handle
> fail_level=getattr(checks, options['fail_level']),
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/base.py",
>  
> line 379, in check
> include_deployment_checks=include_deployment_checks,
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/management/base.py",
>  
> line 366, in _run_checks
> return checks.run_checks(**kwargs)
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/checks/registry.py",
>  
> line 71, in run_checks
> new_errors = check(app_configs=app_configs)
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/checks/urls.py",
>  
> line 13, in check_url_config
> return check_resolver(resolver)
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/checks/urls.py",
>  
> line 23, in check_resolver
> return check_method()
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/urls/resolvers.py",
>  
> line 397, in check
> warnings.extend(check_resolver(pattern))
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/checks/urls.py",
>  
> line 23, in check_resolver
> return check_method()
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/urls/resolvers.py",
>  
> line 397, in check
> warnings.extend(check_resolver(pattern))
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/checks/urls.py",
>  
> line 23, in check_resolver
> return check_method()
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/urls/resolvers.py",
>  
> line 397, in check
> warnings.extend(check_resolver(pattern))
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/core/checks/urls.py",
>  
> line 23, in check_resolver
> return check_method()
>   File 
> "/home/anadon/.cache/pypoetry/virtualenvs/project1-N4OQNeyl-py3.6/lib/python3.6/site-packages/django/urls/resolvers.py",
>  
> line 398, in check
> return warnings or self.pattern.check()
> AttributeError: 'str' object has no attribute 'check'
>
> ```
>

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

Re: how to create a Django project without using an IDE, but using the django-admin startproject command

2019-03-10 Thread nm
As others have pointed out, the problem might be not having your virtual 
env activated.
If it's your first time with Django, there are very clear installation and 
set-up instructions in the Django Girls tutorial - also for Windows. I 
highly recommend it for a start.

On a side note, I'd also recommend using Python 3.x and Django 2.1, if you 
can. Django 1.6 has not been supported for 4 years now, and Python 2.7 
support is going to be dropped soon... and I suppose Django 1.6 may not be 
compatible with Python 3.7 ;)

On Saturday, 9 March 2019 19:15:01 UTC+1, Ando Rakotomanana wrote:
>
> Hello, I'm still starting with django. And I have a problem with the 
> creation of the project, I write: "django-admin startproject DjangoTest" in 
> the cmd of my windows and it tells me that django-admin is not an internal 
> command. While I typed the same code this morning in the cmd and it worked. 
> And I do not understand why?
> I have python 2.7.0 and 3.7.2 and django 1.6.2 installed on my windows 8.1
>

-- 
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/cc6f05e6-a926-4137-b234-3d2563139b7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Use of asyncio

2019-02-07 Thread nm
If you're specifically looking for Django-related uses of asyncio, there's 
Channels  for websockets (and 
other stuff). You can find an example application - a simple chat - in the 
tutorial in the documentation.

W dniu sobota, 2 lutego 2019 03:39:57 UTC+1 użytkownik kannamshivakumar417 
napisał:
>
> Can anyone explain to which applications asyncio used for.
>

-- 
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/8a47b75b-eac0-49fd-ab16-37479001c404%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems from writing test cases.

2018-12-13 Thread nm
Regarding the first question and the problem with retrieving the user with 
`pk=1`:
When you run your tests, Django creates a test database where all the 
objects created by the test cases are stored, and which is destroyed after 
all the tests are run. Each user you create gets a *new* pk. The pk number 
is always incremented, regardless of whether the user with a previous pk 
was deleted in the meantime or not (btw, this works the same in your 
"regular" database, you can try adding and deleting users in the shell and 
see yourself). So when you run both test cases and in each test case you 
create one user, one of them gets `pk=1`, and the other `pk=2`. However, if 
you use the `setUpTestData` method in a test case, all the objects created 
by this methods are deleted after *this test case* finishes. This means 
that the first test case creates a user (pk=1), then this user is deleted, 
and the second test case creates another user (pk=2). Then you try to 
retrieve the user with pk=1, which fails.

By the way, the order in which tests are run is not always the same, so you 
should not rely on it in your tests. Assigning created object to class 
attributes, as you did later, is a much better approach.

Hope this is what you wanted to know (;


W dniu wtorek, 11 grudnia 2018 05:00:07 UTC+1 użytkownik ANi napisał:
>
> Hello,
> I am now trying to write test cases for my project, but I find some 
> problems.
>
> 1.
>
>
> class FirstTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
>User.objects.create(username = 'johndoe', password = 
> 'goodtobehere123')
>...
>
> def test_case_one(self):
>user = User.objects.get(pk=1)
># some assertions here
>
>...
>
> class SecondTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
> User.objects.create(username = 'janedoe', password = 
> 'nicetobethere456')
>
> def test_case_one(self):
>user = User.objects.get(pk=1)
># some assertions here
>
>...
>
>
> If I run all the tests together, I can pass the FirstTest while getting 
> error of "django.contrib.auth.models.DoesNotExist: User matching query does 
> not exist." on the SecondTest.
> If I run two test cases separately, all tests are passed.
> Then solved it by changing it into this:
>
>
> class FirstTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
> cls.user = User.objects.create(username = 'johndoe', password = 
> 'goodtobehere123')
> ...
>
> def test_case_one(self):
>self.assertEqual(self.user.somefunc(), something)
># some assertions here
>
>...
>
> class SecondTest(TestCase):
>
> @classmethod
> def setUpTestData(cls):
>cls.user = User.objects.create(username = 'janedoe', password = 
> 'nicetobethere456')
>...
>
> def test_case_one(self):
>self.assertEqual(self.user.somefunc(), something)
># some assertions here
>
>...
>
>
>
> However I don't know why.?
>
>
> 2.
>
> class ViewTest(TestCase):
>  
> @classmethod
> def setUpTestData(cls):
> cls.user = User.objects.create(username = 'johndoe', password = 
> 'goodtobehere123')
> ...
>
>  def setUp(self):
>  self.item = Item.objects.create(
>  category = 1,
>  item_content = 'content content',
>  )
>
>
>  def test_item_update(self):
>  # the view will update the item and return HTTP status code 200.
>  # if the item is not exist, raise Http404  
>  self.c = Client() 
>  resp = self.c.post(
> reverse('update_item', kwargs={"pk":self.item.pk}),
> data = {
> "category": 2,
> "content": "item content",
>  }
>  )
>
>  self.assertEqual(resp.status_code, 200)
>  self.assertEqual(self.item.category, 2)
>
>  def test_item_delete(self):  
>  # the view will delete the item and return HTTP status code 200.
>  # if the item is not exist, raise Http404  
>  self.c = Client() 
>  resp = self.c.post(
> reverse('delete_item'),
> data = {
> "pk": self.item.pk
>  }
>  )
>
>  self.assertEqual(resp.status_code, 200)
>   
>
>
>
> I got " AssertionError: 1 != 2 ". for test_item_update()
> and "AssertionError: 404 != 200". for test_item_delete()
>
> I think it is reasonable but obviously I misunderstand something. 
>
> Thank you. I will be very happy if you want to help me >___<
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web 

Enable profiling in internal development webserver

2007-01-16 Thread nm


How to enable profiling in internal development webserver?
This http://code.djangoproject.com/wiki/ProfilingDjango doesn't help.

Thanks,
Nuno Mariz



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Pagination too slow in Admin interface

2007-01-12 Thread nm

I have 301220 records in a simple(3 cols) mysql table and in the Admin  
interface the pagination is too slow, even with only 10 records per  
page. There are any reason for this?
Curious, is when I click in a visited page is fast.

Thanks,
Nuno Mariz



--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Hosting a Django project in Bluehost

2006-06-17 Thread nm

Hi all,
I'm trying to run a project hosted in Bluehost, it only supports fcgi.  
I'm an apache guy.
Anyone have a project maded with Django hosted in Bluehost?

Thanks,
Nuno



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Hosting a Django project in Bluehost

2006-06-16 Thread nm

Hi all,
I'm trying to run a project hosted in Bluehost, it only supports fcgi.  
I'm an apache guy.
Anyone have a project maded with Django hosted in Bluehost?

Thanks,
Nuno




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Accessing logged-in user object in models

2006-06-13 Thread nm

Ok,
I will give a try.

Thanks all.
Nuno

Quoting Michael Radziej <[EMAIL PROTECTED]>:

>
> Don Arbow wrote:
>> Then in the view that calls the template, you determine if the user
>> is authorized to edit the field.
>
> You don't have a view function with an Admin page ... that doesn't work.
>
> But you could just redirect the Admin page to a view function (using  
>  the URL config) and from the view then call the Admin after  
> checking  the permissions. How about that? I don't use Admin pages,  
> so I can't  give you any first hand advice.
>
> Michael




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---