Re: deleting a user model that extends abstractuser

2023-02-03 Thread Mike Dewhirst

On 4/02/2023 7:58 am, d07 wrote:


I am trying to delete a user object that belongs to a User class that 
extends AbstractUser. The extending class looks something like this:


class User(AbstractUser):
    name = CharField("Name", blank=True, max_length=255)
    def __str__(self):
        return self.username

When I try to delete a user like this:

user = User.objects.get(pk=self.user_id) user.delete()

The user object is not deleted (at least from checking the user table 
in the database). Other models that have on_delete=models.CASCADE to 
my custom user class are deleted as expected but the actual user 
object is NOT deleted.




Here's a guess ...

The models.CASCADE seems to be working and everything seems fine. So 
when does the vital object at the head of the cascade get deleted?


It has to be when the delete transaction gets committed to the database 
and all the loose ends are cleaned up.


Therefore, some loose end somewhere is preventing transaction completion.

How clean is your User model?


When I try

user = User.objects.get(pk=self.user_id)
user.delete()
user.delete() # adding extra delete()

i.e. an extra user.delete(), then the user object is deleted, but also 
raises an exception (/which is not unexpected/)


User object can't be deleted because its id attribute is set to None.



That says the database needs to clean up some loose ends for which it 
needs the id of the User being deleted.


Does the User model have a foreign key with on_delete = models.SET_NULL

Transactions need to be committed successfully or they roll back.

Good luck

M

but the user object along with other objects with FK relationship to 
the User class are deleted (as expected). Sounds like the object was 
"deleted" the first time I called user.delete()? But I can still see 
the row in my user's table.


Not sure if related but, I see that the type of User to delete 
is  not 
the User model class.


So, I'm trying to delete a user object that extends abstractuser class 
but I'm having to call delete() twice on the object, which is not 
normal (I think), how can I get rid of this?


AbstarctUser is from from django.contrib.auth.models import AbstractUser

--
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/2f4ffda8-2eac-4546-a8fa-276bfb38df8fn%40googlegroups.com 
.



--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.

--
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/cd703c26-1a23-56e2-0a6c-30bcdefa186d%40dewhirst.com.au.


OpenPGP_signature
Description: OpenPGP digital signature


deleting a user model that extends abstractuser

2023-02-03 Thread d07


I am trying to delete a user object that belongs to a User class that 
extends AbstractUser. The extending class looks something like this:
class User(AbstractUser): 
name = CharField("Name", blank=True, max_length=255) 
def __str__(self): 
return self.username 

When I try to delete a user like this:
user = User.objects.get(pk=self.user_id) user.delete() 

The user object is not deleted (at least from checking the user table in 
the database). Other models that have on_delete=models.CASCADE to my custom 
user class are deleted as expected but the actual user object is NOT 
deleted.

When I try
user = User.objects.get(pk=self.user_id) 
user.delete() 
user.delete() # adding extra delete() 

i.e. an extra user.delete(), then the user object is deleted, but also 
raises an exception (*which is not unexpected*)

User object can't be deleted because its id attribute is set to None.

but the user object along with other objects with FK relationship to the 
User class are deleted (as expected). Sounds like the object was "deleted" 
the first time I called user.delete()? But I can still see the row in my 
user's table.

Not sure if related but, I see that the type of User to delete is  not the User model class.

So, I'm trying to delete a user object that extends abstractuser class but 
I'm having to call delete() twice on the object, which is not normal (I 
think), how can I get rid of this?

AbstarctUser is from from django.contrib.auth.models import AbstractUser

-- 
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/2f4ffda8-2eac-4546-a8fa-276bfb38df8fn%40googlegroups.com.


Re: New Django Developer

2023-02-03 Thread adeyinka newton
You can change the upload path of Django Froala Editor to Cloudinary by
using Cloudinary's upload API. Here is an example of how to do this:

Sign up for a Cloudinary account and get your cloud name, API key, and API
secret.

Install the Cloudinary Python library:

settings.py:
===
pip install cloudinary

Add the following settings in your Django settings file:


import os
import cloudinary
import cloudinary.uploader

CLOUDINARY_CLOUD_NAME = "your_cloud_name"
CLOUDINARY_API_KEY = "your_api_key"
CLOUDINARY_API_SECRET = "your_api_secret"

cloudinary.config(
  cloud_name = CLOUDINARY_CLOUD_NAME,
  api_key = CLOUDINARY_API_KEY,
  api_secret = CLOUDINARY_API_SECRET
)



In your Froala Editor view,
use the Cloudinary library to upload the image and return the URL to Froala
Editor.
Here is an example view:


from django.http import JsonResponse
import cloudinary
import cloudinary.uploader

def froala_upload(request):
if request.method == 'POST' and request.FILES.get('file'):
try:
response = cloudinary.uploader.upload(request.FILES['file'])
return JsonResponse({
'link': response['secure_url']
})
except Exception as e:
return JsonResponse({
'error': str(e)
})
return JsonResponse({
'error': 'Invalid request'
})



5.

Add the URL for the Froala upload view in your URL configuration:


from django.urls import path
from .views import froala_upload

urlpatterns = [
path('froala_upload/', froala_upload, name='froala_upload'),
]



6.
In the Froala Editor options, set the imageUploadURL to the URL of your
upload view.
 Here is an example:


$('#froala-editor').froalaEditor({
  imageUploadURL: '/froala_upload/'
});

On Fri, Feb 3, 2023 at 3:58 AM Israel Akinoso  wrote:

> Can we collaborate on one together?
> It'll boost us both :)
>
> On Wednesday, February 1, 2023 at 4:03:40 PM UTC+1 vinodr...@gmail.com
> wrote:
>
>> Hi All, I am recently complete *Django course* with *small projects*,
>> can any one help me to find *real world projects* to master Django,
>> i have basic knowledge about *UI technologies.*
>>
>> --
> 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/e674df39-8626-4403-b294-95ce4f843d57n%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/CAPohmQv34_NHtBovu97dfEdEuO2c6J4Z%2B4QgyjYTnUKq56usQQ%40mail.gmail.com.


Re: Django Froala Editor

2023-02-03 Thread 'Steven Mapes' via Django users
Sorry hit send too soon. An alternative is to update your settings.py entry 
for FROALA_STORAGE_BACKEND to point to a different backend as per their 
docs https://github.com/froala/django-froala-editor#other-settings

On Friday, 3 February 2023 at 14:30:12 UTC Steven Mapes wrote:

> Easiest way will be to overload their default upload view.
>
> If you look in the urls.py for the package it has two entries
>
>
> *path('image_upload/', views.image_upload, 
> name='froala_editor_image_upload'),path('file_upload/', views.file_upload, 
> name='froala_editor_file_upload'),*
>
> Take a look at those view here 
> https://github.com/froala/django-froala-editor/blob/master/froala_editor/views.py
>
> Then create your own views doing what you want but serve them from the URL 
> path that these would be on by default so that they are called instead.
>
> On Friday, 3 February 2023 at 12:00:32 UTC akino...@gmail.com wrote:
>
>> Please I need help on how to change the upload path of django froala 
>> editor. Possiby to Cloudinary 
>> Please I need help 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/39b39288-711b-464a-9f13-e9d3173a62a8n%40googlegroups.com.


Re: Django Froala Editor

2023-02-03 Thread 'Steven Mapes' via Django users
Easiest way will be to overload their default upload view.

If you look in the urls.py for the package it has two entries


*path('image_upload/', views.image_upload, 
name='froala_editor_image_upload'),path('file_upload/', views.file_upload, 
name='froala_editor_file_upload'),*

Take a look at those view 
here 
https://github.com/froala/django-froala-editor/blob/master/froala_editor/views.py

Then create your own views doing what you want but serve them from the URL 
path that these would be on by default so that they are called instead.

On Friday, 3 February 2023 at 12:00:32 UTC akino...@gmail.com wrote:

> Please I need help on how to change the upload path of django froala 
> editor. Possiby to Cloudinary 
> Please I need help 

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


Django Froala Editor

2023-02-03 Thread Israel Akinoso
Please I need help on how to change the upload path of django froala 
editor. Possiby to Cloudinary 
Please I need help 

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


Re: New Django Developer

2023-02-03 Thread Israel Akinoso
Can we collaborate on one together?
It'll boost us both :)

On Wednesday, February 1, 2023 at 4:03:40 PM UTC+1 vinodr...@gmail.com 
wrote:

> Hi All, I am recently complete *Django course* with *small projects*, 
> can any one help me to find *real world projects* to master Django,
> i have basic knowledge about *UI technologies.*
>
>

-- 
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/e674df39-8626-4403-b294-95ce4f843d57n%40googlegroups.com.