Admin - django.auth.group 1to1 comment

2020-09-03 Thread Mike Dewhirst
In the Admin I would like to add an inline comment to django.auth.group
for purposes of documenting the role each group record represents
including why certain permissions have been granted or denied to that
group. In other words, I believe auth.group really needs a comment
TextField.

I've struck a wall and would appreciate any hints. This is what I've done:

1. Created a comment table like this:

from django.db import models


class Comment(models.Model):
    """ Documentation for sets of group permissions. Just in case we
forget. """

    group = models.OneToOneField(
    "auth.Group",
    on_delete=models.CASCADE,
    related_name='groupcomment'
    )
    comment = models.TextField(
    verbose_name='comment',
    default='',
    blank=True,
    help_text='Document this group',
    )
    class Meta:
    verbose_name = 'comment'
    verbose_name_plural = 'comments'

    def __str__(self):
    return '{0} comment'.format(self.group)


2. Made a class in admin.py (in my "common" app which houses my custom
user) like this:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin, Group, GroupAdmin
from django.contrib.admin.options import InlineModelAdmin
from common.models import Comment, User, UserProfile

class MyGroupAdmin(GroupAdmin):

    model = Group

    class CommentInline(admin.StackedInline):
    model = Comment
    extra = 0
    fieldsets = [
    (
    "Comment",
    {
    "description": "Server date/times are UTC rather
than local time",
    "classes": ("",),
    "fields": (
    "comment",
    ),
    },
    ),
    ]
    inlines = ((CommentInline,),)

# omitting UserAdmin etc

admin.site.register(User, UserAdmin)
admin.site.unregister(Group)
admin.site.register(Group, MyGroupAdmin)


3. So the error turns out to be:

ERRORS:
: (admin.E104) 'auth.MyGroupAdmin'
must inherit from 'InlineModelAdmin'.


4. When I import and include 'InlineModelAdmin' like this:

class MyGroupAdmin(GroupAdmin, InlineModelAdmin):
 ...

The error becomes:


  File "D:\Users\mike\envs\xxct3\train\common\admin.py", line 116, in

    admin.site.register(Group, MyGroupAdmin)
  File
"D:\Users\mike\envs\xxct3\lib\site-packages\django\contrib\admin\sites.py",
line 124, in register
    self._registry[model] = admin_class(model, self)
  File
"D:\Users\mike\envs\xxct3\lib\site-packages\django\contrib\admin\options.py",
line 580, in __init__
    super().__init__()
TypeError: __init__() missing 2 required positional arguments:
'parent_model' and 'admin_site'


I have tried using super().__init__() to resolve these errors but the
trail just goes deeper into the forest and I'm scrabbling in the dark at
this stage.

Can anyone please help?

Thanks

Mike



-- 
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/f2704ba9-4127-7462-26d2-c143f2b3459b%40dewhirst.com.au.


Re: DB migration: Loading a massive fixture dump

2020-09-03 Thread Fred Blaise
Just for the follow-up, I ended up using pgloader and after some argument 
tweaking, it worked. Cheers.

On Wednesday, September 2, 2020 at 7:26:04 AM UTC+2 Fred Blaise wrote:

> Hi Mike,
>
> Thanks for the answer.
>
> Yes, I was aware yet hopeful regarding the size.
>
> Regarding the converter, I would be interested to take a look at your py3 
> work, if you could forward it along.
>
> Thanks.
>
>
> On Wed, Sep 2, 2020, 00:21 Fred Blaise  wrote:
>
>> Hi,
>>
>> I have to migrate a database from mysql to postgresql. Unfortunately, 
>> there is quite a bit of data in there.
>>
>> As a strategy, I thought of using Django's ORM feature, dump the data 
>> from my setup using mysql, and load the fixtures on the other setup using 
>> postgresql, such as:
>>
>> # on mysql
>> $ docker exec -ti madchap_ddojo_uwsgi_1 bash -c 'python manage.py 
>> dumpdata --indent=4 -e sessions -e admin --natural-foreign 
>> --natural-primary -e contenttypes -e auth.permission -v2' > 
>> ~/Downloads/datadump_orm_dump_1.json
>>
>> This yields a 4GB json file.
>>
>> Reload on the other side, such as:
>>
>> # on postgresql
>> $  docker exec -ti madchap_ddojo_uwsgi_1 bash -c 'python manage.py 
>> loaddata datadump_orm_dump_small.json'
>>
>> I let the loaddata run for 4hours, and it eventually returns with no 
>> error -- but no success either. I actually now think that the message 
>> indicating "Installed x object(s) from 1 fixture(s)" does not show, I will 
>> see again.
>>
>> Looking at the postgresql side, querying metatables such as:
>>
>> SELECT nspname || '.' || relname AS "relation",
>> pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
>>   FROM pg_class C
>>   LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
>>   WHERE nspname NOT IN ('pg_catalog', 'information_schema')
>> AND C.relkind <> 'i'
>> AND nspname !~ '^pg_toast'
>>   ORDER BY pg_total_relation_size(C.oid) DESC
>>   LIMIT 5;
>>
>> tells me loads of data gets in there. a "\d+" does not agree, however 
>> (weird, but I don't know enough to get the difference between the two). And 
>> yet, I cannot see anything through any SELECT statement (hinting to the 
>> transaction isolation).
>>
>> All things equal, this strategy works fine when working with small json 
>> files. I just successfully did it with a file less than 1MB.
>>
>> I am guessing I have a few questions, I am stuck here.
>>
>> 1. Are there any hidden args/switches to manage.py loaddata or else that 
>> I could look at?
>> 2. Are there specific django configuration that could help me load the 
>> data?
>> 3. Does a loaddata actually result in a massive single transaction? 
>> (looks like so, sounds crazy to me :))
>> 4. Is there a better way to migrate my data?
>>
>> Thanks a lot for any pointers!
>> Cheers.
>>
>> -- 
>>
> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>>
> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/d6f5e874-e96b-4984-b69d-d7857e95a0a4n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e005a6c1-07ef-4fc5-99ca-1e3e44b58f5en%40googlegroups.com.


Re: DJANGO ADMINISTRATION ERROR & TemplateDoesNotExist

2020-09-03 Thread King Niko
Okay, so I fixed everything with Django Logging- including getting the
pictures to show up in the store.

However, one thing still remains - recognizing the *store/cart.html* and
*store/checkout.html*

To get the pictures to appear from the DJANGO ADMINISTRATION, I used the
following:


urlpatterns = [
path('admin/', admin.site.urls),
path('', include('store.urls')),
url(r'^images/(?P.)$', serve,{'document_root':
settings.MEDIA_ROOT}),
url(r'^static/(?P.)$', serve,{'document_root':
settings.STATIC_ROOT}),


]

I also tested this to get the *cart.html* and *checkout.html* to stop
showing a TemplateDoesNotExist 500 Server Error:


urlpatterns = [
path('admin/', admin.site.urls),
path('', include('store.urls')),
url(r'^images/(?P.)$', serve,{'document_root':
settings.MEDIA_ROOT}),
url(r'^static/(?P.)$', serve,{'document_root':
settings.STATIC_ROOT}),
url(r'^cart/(?P.)$', serve,{'document_root':
'/store/templates/store'}),
url(r'^checkout/(?P.)$', serve,{'document_root':
'/store/templates/store'}),


]

But still no success. Any suggestions?



On Wed, Sep 2, 2020 at 6:07 PM Kasper Laudrup  wrote:

> Hi King Niko,
>
> On 02/09/2020 17.46, King Niko wrote:
> > *I have not managed to get the Django log up and running, but this may
> > help to get guidance on resolving the issue:*
> >
>
> You should get access to the Django log. It's pointless to waste time on
> guessing what might be wrong when you could have a log file pointing you
> to exactly the line of code which is the cause of your error.
>
> Anyway, regarding your code:
>
> >  try:
> >  cart = json.loads(request.COOKIES['cart'])
> >  except:
>
> Only catch the exceptions you actually expect to be thrown and know how
> to handle. Catching all potential exceptions like you're doing here will
> potentially silence a lot of errors making it much harder for you to
> debug any issues that might occur later on because you ignored the
> original error.
>
> >  except:
> >  pass
>
> This is even more problematic. Here you are simply ignoring any
> exceptions that might be thrown again making it extremely hard to debug
> since you'll just get exceptions or "weird" behavior later on.
>
> Instead of trying to guess what might be wrong, you're lucky enough to
> be using an interpreted language (Python) that can give you some very
> precise error messages if you stop ignoring the errors and get access to
> the logs which will show exactly what went wrong.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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/76612162-ff10-06ea-84e5-8a52a31e45e6%40stacktrace.dk
> .
>

-- 
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/CAO1EWpH4pQwLMyyF15uCFJCTGJanRdnWcb2bhvrnhnFx1mP%2BVA%40mail.gmail.com.


Re: DJANGO ADMINISTRATION ERROR & TemplateDoesNotExist

2020-09-03 Thread Kasper Laudrup

Hi King Niko,

On 03/09/2020 13.44, King Niko wrote:
Okay, so I fixed everything with Django Logging- including getting the 
pictures to show up in the store.




What's written in the Django logs when you get the 500 errors?

Kind regards,

Kasper Laudrup

--
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/40fd1120-91a7-d7e3-f08e-9c082aff5ea6%40stacktrace.dk.


Re: DJANGO ADMINISTRATION ERROR & TemplateDoesNotExist

2020-09-03 Thread King Niko
Hi Kasper,

I am getting the following error:

raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: ./store/cart.html

How can the template not exist if the other templates exist? Lol, it seems
impossible.


On Thu, Sep 3, 2020 at 8:31 AM Kasper Laudrup  wrote:

> Hi King Niko,
>
> On 03/09/2020 13.44, King Niko wrote:
> > Okay, so I fixed everything with Django Logging- including getting the
> > pictures to show up in the store.
> >
>
> What's written in the Django logs when you get the 500 errors?
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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/40fd1120-91a7-d7e3-f08e-9c082aff5ea6%40stacktrace.dk
> .
>

-- 
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/CAO1EWpEi-b4q%2BH6229Gyru%3DZJtJawWyaTQ%2BCJf8G_gf7HfPZiw%40mail.gmail.com.


ValueError... Cannot query "User": Must be "Model" instance.

2020-09-03 Thread Abdu-H
 

Hello,

I am working on an app where car owner will list their car and drivers 
interested in renting them will make a request to rent the cars…

i basically have three models the *users*(car owners and drivers) *car* 
listed by owners, and *rent, *i have a listView to list all the car 
available and a detailView for each car, i have a button on the detailed 
view, when clicked i want it to take some of the information on the 
detailed view and save it in the* rent *model… But i am getting a 
ValueError (Cannot query "testuser1": Must be "Listing" instance). But i 
also need to store the driver(testuser1 in this case) in the Rent model. 

Thanks in advance... any help is hugely appreciated

Below are my view.py, models.py and error messages:



*view.py*

class ListingDetailView(DetailView):

model = Listing


def post_rent(self, request, pk, *args, **kwargs):

user = request.User

listing = get_object_or_404(Listing, pk=pk)

rent, created = Rent.objects.get_or_create(

car_owner=listing.car_owner,

driver=request.user,

car_id=listing.pk)

rent.save(request.POST)

messages.info(request, *"Rent request has been made succesfully."*)

return redirect(*'/'*)



*models.py*

class Listing(models.Model):

DEF_YEAR = *'2003'*

CAR_YEAR_CHOICES = [(*'2002'*, *'2002'*), (*'2003'*, *'2003'*), (
*'2004'*, *'2004'*), (*'2005'*, *'2005'*),

(*'2006'*, *'2006'*), (*'2007'*, *'2007'*), (
*'2008'*, *'2008'*), (*'2009'*, *'2009'*),

(*'2010'*, *'2010'*), (*'2011'*, *'2011'*), (
*'2012'*, *'2012'*), (*'2013'*, *'2013'*),

(*'2014'*, *'2014'*), (*'2015'*, *'2015'*), (
*'2016'*, *'2016'*), (*'2017'*, *'2017'*),

(*'2018'*, *'2018'*), (*'2019'*, *'2019'*), (
*'2020'*, *'2020'*), ]


NEW = *'New'*

USED = *'Used'*

OLD = *'Old'*

CAR_CONDITION_CHOICES = [(*'NEW'*, *'New'*), (*'USED'*, *'Used'*), (
*'OLD'*, *'Old'*)]


car_owner = models.ForeignKey(User, on_delete=models.CASCADE)

car_make = models.CharField(max_length=50)

car_model = models.CharField(max_length=50)

car_year = models.CharField(max_length=4, choices=CAR_YEAR_CHOICES, 
default=DEF_YEAR)

car_condition = models.CharField(max_length=4, 
choices=CAR_CONDITION_CHOICES, default=OLD)

car_pic1 = models.ImageField(default=*'car.png'*, upload_to=
*"car_listing-photos"*)

weekly_charges = models.FloatField()


def __str__(self):

return *f'*{self.car_year}  {self.car_make}  {self.car_model}*'*


def get_absolute_url(self):

return reverse(*'listing-detail'*, kwargs={*'pk'*: self.pk})



class Rent(models.Model):

car_id = models.BigIntegerField(null=True, blank=True)

car_owner = models.ForeignKey(Listing, on_delete=models.SET_NULL, 
null=True, blank=True)

driver = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, 
blank=True)

start_date = models.DateField(null=True, blank=True)

end_date = models.DateField(null=True, blank=True)

approved = models.BooleanField(default=False)


*listing_detail.html*



{% csrf_token %}

Rent 
Car

 



*Error Message*


*ValueError at /listing/2/*

Cannot query "testuser1": Must be "Listing" instance.

*Request Method:*

POST

*Request URL:*

http://127.0.0.1:8000/listing/2/

*Django Version:*

3.1

*Exception Type:*

ValueError

*Exception Value:*

Cannot query "testuser1": Must be "Listing" instance.


*More Error Dump:*


Environment:



Request Method: POST

Request URL: http://127.0.0.1:8000/listing/2/


Django Version: 3.1

Python Version: 3.8.5

Installed Applications:

['accounts.apps.AccountsConfig',

 'django.contrib.admin',

 'django.contrib.auth',

 'django.contrib.contenttypes',

 'django.contrib.sessions',

 'django.contrib.messages',

 'django.contrib.staticfiles',

 'app.apps.AppConfig',

 'crispy_forms']

Installed 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']




Traceback (most recent call last):

  File 
"/Users/ChuzzyOfficial/PycharmProjects/djangoProject/instarydes/.venv/lib/python3.8/site-packages/django/core/handlers/exception.py",
 
line 47, in inner

response = get_response(request)

  File 
"/Users/ChuzzyOfficial/PycharmProjects/djangoProject/instarydes/.venv/lib/python3.8/site-packages/django/core/handlers/base.py",
 
line 179, in _get_response

response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File 
"/Users/ChuzzyOfficial/PycharmProjects/djangoProject/instarydes/.venv/lib/python3.8/site-packages/django/views/generic/base.py",
 
lin

ValueError... Cannot query "User": Must be "Model" instance.

2020-09-03 Thread Abdulhameed Giwa
Hello,

I am working on an app where car owners will list their car and drivers
interested in renting them will make a request to rent the cars…

i basically have three models the *users*(car owners and drivers) *car* listed
by owners, and *rent, *i have a listView to list all the car available and
a detailView for each car, i have a button on the detailed view, when
clicked i want it to take some of the information on the detailed view and
save it in the* rent *model… But i am getting a ValueError (Cannot query
"testuser1": Must be "Listing" instance). But i also need to store the
driver(testuser1 in this case) in the Rent model.

Below are my view.py, models.py and error messages:




*view.py*

class ListingDetailView(DetailView):

model = Listing


def post_rent(self, request, pk, *args, **kwargs):

user = request.User

listing = get_object_or_404(Listing, pk=pk)

rent, created = Rent.objects.get_or_create(

car_owner=listing.car_owner,

driver=request.user,

car_id=listing.pk)

rent.save(request.POST)

messages.info(request, *"Rent request has been made succesfully."*)

return redirect(*'/'*)



*models.py*

class Listing(models.Model):

DEF_YEAR = *'2003'*

CAR_YEAR_CHOICES = [(*'2002'*, *'2002'*), (*'2003'*, *'2003'*), (
*'2004'*, *'2004'*), (*'2005'*, *'2005'*),

(*'2006'*, *'2006'*), (*'2007'*, *'2007'*), (
*'2008'*, *'2008'*), (*'2009'*, *'2009'*),

(*'2010'*, *'2010'*), (*'2011'*, *'2011'*), (
*'2012'*, *'2012'*), (*'2013'*, *'2013'*),

(*'2014'*, *'2014'*), (*'2015'*, *'2015'*), (
*'2016'*, *'2016'*), (*'2017'*, *'2017'*),

(*'2018'*, *'2018'*), (*'2019'*, *'2019'*), (
*'2020'*, *'2020'*), ]


NEW = *'New'*

USED = *'Used'*

OLD = *'Old'*

CAR_CONDITION_CHOICES = [(*'NEW'*, *'New'*), (*'USED'*, *'Used'*), (
*'OLD'*, *'Old'*)]


car_owner = models.ForeignKey(User, on_delete=models.CASCADE)

car_make = models.CharField(max_length=50)

car_model = models.CharField(max_length=50)

car_year = models.CharField(max_length=4, choices=CAR_YEAR_CHOICES,
default=DEF_YEAR)

car_condition = models.CharField(max_length=4,
choices=CAR_CONDITION_CHOICES, default=OLD)

car_pic1 = models.ImageField(default=*'car.png'*, upload_to=
*"car_listing-photos"*)

weekly_charges = models.FloatField()


def __str__(self):

return *f'*{self.car_year}  {self.car_make}  {self.car_model}*'*


def get_absolute_url(self):

return reverse(*'listing-detail'*, kwargs={*'pk'*: self.pk})



class Rent(models.Model):

car_id = models.BigIntegerField(null=True, blank=True)

car_owner = models.ForeignKey(Listing, on_delete=models.SET_NULL,
null=True, blank=True)

driver = models.ForeignKey(User, on_delete=models.SET_NULL, null=True,
blank=True)

start_date = models.DateField(null=True, blank=True)

end_date = models.DateField(null=True, blank=True)

approved = models.BooleanField(default=False)


*listing_detail.html*



{% csrf_token %}

Rent
Car

 


*Error Message*


*ValueError at /listing/2/*

Cannot query "testuser1": Must be "Listing" instance.


*Request Method:*


POST


*Request URL:*


http://127.0.0.1:8000/listing/2/


*Django Version:*


3.1


*Exception Type:*


ValueError


*Exception Value:*


Cannot query "testuser1": Must be "Listing" instance.


*More Error Dump:*


Environment:



Request Method: POST

Request URL: http://127.0.0.1:8000/listing/2/


Django Version: 3.1

Python Version: 3.8.5

Installed Applications:

['accounts.apps.AccountsConfig',

 'django.contrib.admin',

 'django.contrib.auth',

 'django.contrib.contenttypes',

 'django.contrib.sessions',

 'django.contrib.messages',

 'django.contrib.staticfiles',

 'app.apps.AppConfig',

 'crispy_forms']

Installed 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']




Traceback (most recent call last):

  File
"/Users/ChuzzyOfficial/PycharmProjects/djangoProject/instarydes/.venv/lib/python3.8/site-packages/django/core/handlers/exception.py",
line 47, in inner

response = get_response(request)

  File
"/Users/ChuzzyOfficial/PycharmProjects/djangoProject/instarydes/.venv/lib/python3.8/site-packages/django/core/handlers/base.py",
line 179, in _get_response

response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File
"/Users/ChuzzyOfficial/PycharmProjects/djangoProject/instarydes/.venv/lib/python3.8/site-packages/django/views/generic/base.py",
line 73, in view

return self.dispatch(request, *args, **kwargs)


Potential Bug in django.contrib.gis

2020-09-03 Thread Janis Goldzycher

Hi all,
I recently upgraded django 1.11 to 3.1. Now, in dango 3.1, the following 
example code from 
https://docs.djangoproject.com/en/3.1/ref/contrib/gis/geos/#django.contrib.gis.geos.Polygon
produces a Segfault. 

Code snippet:
>>> from django.contrib.gis.geos import Point, LineString, Polygon, 
LinearRing
>>> ext_coords = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))
>>> int_coords = ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 
0.4))
>>> poly = Polygon(ext_coords, int_coords)
>>> [c for c in poly]
[, ]
>>> [c for c in poly[0]]
Segmentation fault (core dumped)

I can also provoke this error with next():
>>> from django.contrib.gis.geos import Point, LineString, Polygon, 
LinearRing
>>> ext_coords = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))
>>> int_coords = ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 
0.4))
>>> poly = Polygon(ext_coords, int_coords)
>>> next(poly[0].__iter__())
Segmentation fault (core dumped)

Is this a bug or might there be another reason (e.g. hardware-related 
issue)?

Thanks, 
Janis

-- 
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/f204bcbb-fd18-44af-83de-917377b9d465n%40googlegroups.com.


Re: ValueError... Cannot query "User": Must be "Model" instance.

2020-09-03 Thread RANGA BHARATH JINKA
Hi,
Go through this. This will help you. The error is because of
foreign key.

https://stackoverflow.com/questions/37839867/django-error-cannot-assign-must-be-an-instance

On Thu, Sep 3, 2020 at 8:46 PM Abdu-H  wrote:

> Hello,
>
> I am working on an app where car owner will list their car and drivers
> interested in renting them will make a request to rent the cars…
>
> i basically have three models the *users*(car owners and drivers) *car*
> listed by owners, and *rent, *i have a listView to list all the car
> available and a detailView for each car, i have a button on the detailed
> view, when clicked i want it to take some of the information on the
> detailed view and save it in the* rent *model… But i am getting a
> ValueError (Cannot query "testuser1": Must be "Listing" instance). But i
> also need to store the driver(testuser1 in this case) in the Rent model.
>
> Thanks in advance... any help is hugely appreciated
>
> Below are my view.py, models.py and error messages:
>
>
>
> *view.py*
>
> class ListingDetailView(DetailView):
>
> model = Listing
>
>
> def post_rent(self, request, pk, *args, **kwargs):
>
> user = request.User
>
> listing = get_object_or_404(Listing, pk=pk)
>
> rent, created = Rent.objects.get_or_create(
>
> car_owner=listing.car_owner,
>
> driver=request.user,
>
> car_id=listing.pk)
>
> rent.save(request.POST)
>
> messages.info(request, *"Rent request has been made succesfully."*
> )
>
> return redirect(*'/'*)
>
>
>
> *models.py*
>
> class Listing(models.Model):
>
> DEF_YEAR = *'2003'*
>
> CAR_YEAR_CHOICES = [(*'2002'*, *'2002'*), (*'2003'*, *'2003'*), (
> *'2004'*, *'2004'*), (*'2005'*, *'2005'*),
>
> (*'2006'*, *'2006'*), (*'2007'*, *'2007'*), (
> *'2008'*, *'2008'*), (*'2009'*, *'2009'*),
>
> (*'2010'*, *'2010'*), (*'2011'*, *'2011'*), (
> *'2012'*, *'2012'*), (*'2013'*, *'2013'*),
>
> (*'2014'*, *'2014'*), (*'2015'*, *'2015'*), (
> *'2016'*, *'2016'*), (*'2017'*, *'2017'*),
>
> (*'2018'*, *'2018'*), (*'2019'*, *'2019'*), (
> *'2020'*, *'2020'*), ]
>
>
> NEW = *'New'*
>
> USED = *'Used'*
>
> OLD = *'Old'*
>
> CAR_CONDITION_CHOICES = [(*'NEW'*, *'New'*), (*'USED'*, *'Used'*), (
> *'OLD'*, *'Old'*)]
>
>
> car_owner = models.ForeignKey(User, on_delete=models.CASCADE)
>
> car_make = models.CharField(max_length=50)
>
> car_model = models.CharField(max_length=50)
>
> car_year = models.CharField(max_length=4, choices=CAR_YEAR_CHOICES,
> default=DEF_YEAR)
>
> car_condition = models.CharField(max_length=4,
> choices=CAR_CONDITION_CHOICES, default=OLD)
>
> car_pic1 = models.ImageField(default=*'car.png'*, upload_to=
> *"car_listing-photos"*)
>
> weekly_charges = models.FloatField()
>
>
> def __str__(self):
>
> return *f'*{self.car_year}  {self.car_make}  {self.car_model}*'*
>
>
> def get_absolute_url(self):
>
> return reverse(*'listing-detail'*, kwargs={*'pk'*: self.pk})
>
>
>
> class Rent(models.Model):
>
> car_id = models.BigIntegerField(null=True, blank=True)
>
> car_owner = models.ForeignKey(Listing, on_delete=models.SET_NULL,
> null=True, blank=True)
>
> driver = models.ForeignKey(User, on_delete=models.SET_NULL, null=True,
> blank=True)
>
> start_date = models.DateField(null=True, blank=True)
>
> end_date = models.DateField(null=True, blank=True)
>
> approved = models.BooleanField(default=False)
>
>
> *listing_detail.html*
>
> 
>
> {% csrf_token %}
>
> Rent
> Car
>
>  
>
>
>
> *Error Message*
>
>
> *ValueError at /listing/2/*
>
> Cannot query "testuser1": Must be "Listing" instance.
>
> *Request Method:*
>
> POST
>
> *Request URL:*
>
> http://127.0.0.1:8000/listing/2/
>
> *Django Version:*
>
> 3.1
>
> *Exception Type:*
>
> ValueError
>
> *Exception Value:*
>
> Cannot query "testuser1": Must be "Listing" instance.
>
>
> *More Error Dump:*
>
>
> Environment:
>
>
>
> Request Method: POST
>
> Request URL: http://127.0.0.1:8000/listing/2/
>
>
> Django Version: 3.1
>
> Python Version: 3.8.5
>
> Installed Applications:
>
> ['accounts.apps.AccountsConfig',
>
>  'django.contrib.admin',
>
>  'django.contrib.auth',
>
>  'django.contrib.contenttypes',
>
>  'django.contrib.sessions',
>
>  'django.contrib.messages',
>
>  'django.contrib.staticfiles',
>
>  'app.apps.AppConfig',
>
>  'crispy_forms']
>
> Installed 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']
>
>
>
>
> Traceback (most recent call last):
>
>   File
> "/Users/ChuzzyOfficial/PycharmPr

Re: Potential Bug in django.contrib.gis

2020-09-03 Thread Janis
Additional Info: I get this behavious in python 3.6.7, which according to 
the documentation should be compatible with django 3.1.

Janis schrieb am Donnerstag, 3. September 2020 um 17:16:50 UTC+2:

>
> Hi all,
> I recently upgraded django 1.11 to 3.1. Now, in dango 3.1, the following 
> example code from 
> https://docs.djangoproject.com/en/3.1/ref/contrib/gis/geos/#django.contrib.gis.geos.Polygon
> produces a Segfault. 
>
> Code snippet:
> >>> from django.contrib.gis.geos import Point, LineString, Polygon, 
> LinearRing
> >>> ext_coords = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))
> >>> int_coords = ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 
> 0.4))
> >>> poly = Polygon(ext_coords, int_coords)
> >>> [c for c in poly]
> [,  0x7f4796e4f2b8>]
> >>> [c for c in poly[0]]
> Segmentation fault (core dumped)
>
> I can also provoke this error with next():
> >>> from django.contrib.gis.geos import Point, LineString, Polygon, 
> LinearRing
> >>> ext_coords = ((0, 0), (0, 1), (1, 1), (1, 0), (0, 0))
> >>> int_coords = ((0.4, 0.4), (0.4, 0.6), (0.6, 0.6), (0.6, 0.4), (0.4, 
> 0.4))
> >>> poly = Polygon(ext_coords, int_coords)
> >>> next(poly[0].__iter__())
> Segmentation fault (core dumped)
>
> Is this a bug or might there be another reason (e.g. hardware-related 
> issue)?
>
> Thanks, 
> Janis
>

-- 
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/3f739f4a-84ce-4ed2-a615-70dc5096e498n%40googlegroups.com.


Re: How to get client or user side details

2020-09-03 Thread Salima Begum
Hi, RANGA BHARATH JINKA
I need any library in python or django.

Thank you

On Wed, Sep 2, 2020 at 10:31 PM RANGA BHARATH JINKA <
bharathjink...@gmail.com> wrote:

> Hi,
>
> There is a javascript library called Detect.js
> Detect.js Github: https://github.com/darcyclarke/Detect.js
> Video Tutorial : https://youtu.be/QukFW1qymSA
>
> All the best
>
>
> On Thu, Sep 3, 2020 at 10:49 AM Salima Begum 
> wrote:
>
>> Hi,
>> We are trying to extract new login attempts done by application users
>> from new devices. That means if an application user tries to login other
>> than their regular devices ( laptop, mobile phone etc.), we need to extract
>> that particular new device details. So the details that we need are
>> 1. Browser Name
>> 2. IP address of the client's device
>> 3. Location from where login is attempted
>> 4. Date and Time Stamp
>>
>> Is there any suitable and latest package available in Django to achieve
>> the above use case?
>>
>> Thank You
>> ~ Salima
>>
>> --
>> 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/CAMSz6b%3D0-LT69BroKq3u%3DOsG5NaVNNkzoRhW5pvMuAp%2BNOrZNA%40mail.gmail.com
>> 
>> .
>>
>
>
> --
> Thanks and Regards
>
> J. Ranga Bharath
> cell: 9110334114
>
> --
> 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/CAK5m316WMfJPXpC9Z7Y_hsnuToReB60SKj5rgvkhM_qD_mH8AQ%40mail.gmail.com
> 
> .
>

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


Re: unexpected change

2020-09-03 Thread rbarh...@gmail.com
Yeah, well great advice.  Too bad I didn't take it sooner.  I lost two 
weeks of really hard work because I move a folder and somehow it erased all 
the coding I had done in PyCharm.  I don't understand it, but there it is. 
 I am in the process of learning how to use Git and Github.  But.  Damn.

On Monday, August 31, 2020 at 11:58:11 AM UTC-7 Kasper Laudrup wrote:

> Hi rbarhydtsf,
>
> On 31/08/2020 20.21, rbarh...@gmail.com wrote:
> > Thank you, Kasper.  Good idea.  Sadly, I don't really know how to do 
> that.
> > 
>
> I would recommend finding some tutorial on how to use git (as that is 
> probably what you'll use anyway). Cannot really recommend anything 
> specific, but someone else might be able to.
>
> It takes some time to learn even the basics and it might seem useless as 
> it is time not spend on writing code, but it can save you so much time 
> later on, so it's definitely worth it.
>
> Has helped me many times in frustrating situations like the one you have 
> right now, and you will have situations like that again, even after many 
> years of writing code.
>
> We're only humans after all and most of us cannot remember the point of 
> the code we wrote two days ago, so it's extremely helpful to have tools 
> to help you remind you what you did (and why) two years ago.
>
> Kind regards,
>
> Kasper Laudrup
>

-- 
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/b5a51ad7-d4e1-4fa4-8ee2-cff352bcde13n%40googlegroups.com.


Re: unexpected change

2020-09-03 Thread Shaheed Haque
Sorry to hear about your problems. One other avenue to possibly explore is
Pycharm's "local history" facility. This keeps track of changes
independently of any VCS such as git.

It seems to be based on the original file paths. So, try creating one file
with the EXACT path before the rename. Then go into the local history
viewer. If you're in luck, you can try to recover the missing content. If
that works, try the other files.

On Thu, 3 Sep 2020, 17:11 rbarh...@gmail.com,  wrote:

> Yeah, well great advice.  Too bad I didn't take it sooner.  I lost two
> weeks of really hard work because I move a folder and somehow it erased all
> the coding I had done in PyCharm.  I don't understand it, but there it is.
> I am in the process of learning how to use Git and Github.  But.  Damn.
>
> On Monday, August 31, 2020 at 11:58:11 AM UTC-7 Kasper Laudrup wrote:
>
>> Hi rbarhydtsf,
>>
>> On 31/08/2020 20.21, rbarh...@gmail.com wrote:
>> > Thank you, Kasper.  Good idea.  Sadly, I don't really know how to do
>> that.
>> >
>>
>> I would recommend finding some tutorial on how to use git (as that is
>> probably what you'll use anyway). Cannot really recommend anything
>> specific, but someone else might be able to.
>>
>> It takes some time to learn even the basics and it might seem useless as
>> it is time not spend on writing code, but it can save you so much time
>> later on, so it's definitely worth it.
>>
>> Has helped me many times in frustrating situations like the one you have
>> right now, and you will have situations like that again, even after many
>> years of writing code.
>>
>> We're only humans after all and most of us cannot remember the point of
>> the code we wrote two days ago, so it's extremely helpful to have tools
>> to help you remind you what you did (and why) two years ago.
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
> --
> 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/b5a51ad7-d4e1-4fa4-8ee2-cff352bcde13n%40googlegroups.com
> 
> .
>

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


Re: unexpected change

2020-09-03 Thread Shaheed Haque
To clarify, try creating an empty file (e.g. using the "touch" command)
with the right path.

On Thu, 3 Sep 2020, 17:39 Shaheed Haque,  wrote:

> Sorry to hear about your problems. One other avenue to possibly explore is
> Pycharm's "local history" facility. This keeps track of changes
> independently of any VCS such as git.
>
> It seems to be based on the original file paths. So, try creating one file
> with the EXACT path before the rename. Then go into the local history
> viewer. If you're in luck, you can try to recover the missing content. If
> that works, try the other files.
>
> On Thu, 3 Sep 2020, 17:11 rbarh...@gmail.com, 
> wrote:
>
>> Yeah, well great advice.  Too bad I didn't take it sooner.  I lost two
>> weeks of really hard work because I move a folder and somehow it erased all
>> the coding I had done in PyCharm.  I don't understand it, but there it is.
>> I am in the process of learning how to use Git and Github.  But.  Damn.
>>
>> On Monday, August 31, 2020 at 11:58:11 AM UTC-7 Kasper Laudrup wrote:
>>
>>> Hi rbarhydtsf,
>>>
>>> On 31/08/2020 20.21, rbarh...@gmail.com wrote:
>>> > Thank you, Kasper.  Good idea.  Sadly, I don't really know how to do
>>> that.
>>> >
>>>
>>> I would recommend finding some tutorial on how to use git (as that is
>>> probably what you'll use anyway). Cannot really recommend anything
>>> specific, but someone else might be able to.
>>>
>>> It takes some time to learn even the basics and it might seem useless as
>>> it is time not spend on writing code, but it can save you so much time
>>> later on, so it's definitely worth it.
>>>
>>> Has helped me many times in frustrating situations like the one you have
>>> right now, and you will have situations like that again, even after many
>>> years of writing code.
>>>
>>> We're only humans after all and most of us cannot remember the point of
>>> the code we wrote two days ago, so it's extremely helpful to have tools
>>> to help you remind you what you did (and why) two years ago.
>>>
>>> Kind regards,
>>>
>>> Kasper Laudrup
>>>
>> --
>> 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/b5a51ad7-d4e1-4fa4-8ee2-cff352bcde13n%40googlegroups.com
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHAc2jeBJJ57o%2BLsjQERj0zicFCLcbEBmnQjKw-Nuypbfd6%2BPA%40mail.gmail.com.


Django+DjangoRestFramework+React+Redux

2020-09-03 Thread Yogendra Yadav
Anyone please suggest some good GitHub repos to learn the subject 
combination

-- 
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/c3604b2a-6824-479f-9511-eb5edbad86bfn%40googlegroups.com.


Re: Django+DjangoRestFramework+React+Redux

2020-09-03 Thread Gerardo Palazuelos Guerrero
search for Brad Traversy's Django + React series of videos in YouTube

--
Gerardo Palazuelos Guerrero



On Thu, Sep 3, 2020 at 12:42 PM Yogendra Yadav 
wrote:

> Anyone please suggest some good GitHub repos to learn the subject
> combination
>
> --
> 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/c3604b2a-6824-479f-9511-eb5edbad86bfn%40googlegroups.com
> 
> .
>

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


Re: DJANGO ADMINISTRATION ERROR & TemplateDoesNotExist

2020-09-03 Thread King Niko
RESOLVED. I managed to fix it.

The problem .. Was so obvious. In *views.py* I did not provide the*
cart.html *and *checkout.html* with the same configurations as *store.html*.
Thus, this caused the 500 server errors. I hope that this thread can help
anyone in the future that encounters a similar predicament.

Thank you all for the assistance.

On Thu, Sep 3, 2020 at 9:43 AM King Niko 
wrote:

> Hi Kasper,
>
> I am getting the following error:
>
> raise TemplateDoesNotExist(template_name, chain=chain)
> django.template.exceptions.TemplateDoesNotExist: ./store/cart.html
>
> How can the template not exist if the other templates exist? Lol, it seems
> impossible.
>
>
> On Thu, Sep 3, 2020 at 8:31 AM Kasper Laudrup 
> wrote:
>
>> Hi King Niko,
>>
>> On 03/09/2020 13.44, King Niko wrote:
>> > Okay, so I fixed everything with Django Logging- including getting the
>> > pictures to show up in the store.
>> >
>>
>> What's written in the Django logs when you get the 500 errors?
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
>> --
>> 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/40fd1120-91a7-d7e3-f08e-9c082aff5ea6%40stacktrace.dk
>> .
>>
>

-- 
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/CAO1EWpFp7EBVMj%3Dr44BEY030Oc45BmHvzjtmFdkGmBZHk9MiuQ%40mail.gmail.com.


Re: Django+DjangoRestFramework+React+Redux

2020-09-03 Thread Yogendra Yadav
Please suggest some open source projects for the same combination

On Fri, Sep 4, 2020 at 12:25 AM Gerardo Palazuelos Guerrero <
gerardo.palazue...@gmail.com> wrote:

> search for Brad Traversy's Django + React series of videos in YouTube
>
> --
> Gerardo Palazuelos Guerrero
>
>
>
> On Thu, Sep 3, 2020 at 12:42 PM Yogendra Yadav 
> wrote:
>
>> Anyone please suggest some good GitHub repos to learn the subject
>> combination
>>
>> --
>> 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/c3604b2a-6824-479f-9511-eb5edbad86bfn%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJ8iCyO3qdSme%2BajBJ9kwpyKrdJK21AwSse0YD16nku4MmGDDQ%40mail.gmail.com
> 
> .
>

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