Re: Search & replace an object in the database

2022-01-24 Thread jools
Thanks! I’ll consider this.

The whole thing is supposed to be a tool for everyday work (although: a 
very dangerous one!), so the “fix the database once” strategy isn’t going 
to work for me.

I’ve added some tests for checking different relation types (m2m, fk, 
one-to-one, generic relation, parent-child links) and it seems to work 
fine; I tested using a bunch of complex records from production.

> If this is not a one-time thing, then you might consider doing something 
similar through the admin interface, but breaking the problem down into 
separate phases using intermediate models. Then you could review each 
possible merge before going on to the next phase of actually doing a merge, 
or choosing to ignore a merge candidate. You could also do additional 
screening to, for example, select *which* customer record should be 
considered complete and which ones should be retired.

That’s a good point. I think I’ll do something similar but more simple by 
providing an overview of all merges beforehand. This way, people will know 
what’s going to happen and have an opportunity to fix any issues upfront.

cheers, j

Thomas schrieb am Freitag, 21. Januar 2022 um 23:37:11 UTC+1:

> Yes this exactly. A couple of possible additions:
>
> I’ve had great luck using python and SQL queries to manipulate a database 
> including converting from other schemas and merging duplicate records.
>
> Make a test database from your backup, and beat it up with your scripted 
> code until you are happy with the result. Just keep deleting the test 
> database and reconstructing it from the backup to try again. The python 
> code can do things easily such as sucking in all records, looking for 
> overlaps on various fields, and merging the results.
>
> If this is not a one-time thing, then you might consider doing something 
> similar through the admin interface, but breaking the problem down into 
> separate phases using intermediate models. Then you could review each 
> possible merge before going on to the next phase of actually doing a merge, 
> or choosing to ignore a merge candidate. You could also do additional 
> screening to, for example, select *which* customer record should be 
> considered complete and which ones should be retired.
>
> hth
>
> - Tom
>
> On Jan 21, 2022, at 12:16 PM, Bernard Mallala  wrote:
>
> I would approach this differently and from the database side mostly
>
>1. Backup the database so you can restore if something happens
>2. In Django, Create an an empty copy of the Customer database e.g 
>CustomerB
>3. Using a SQL query tool, select all duplicate copies from Customer 
>and insert into CustomerB
>4. If needed, update the model for CustomerB so that you are able to 
>associate or reference every duplicate in CustomerB with the right record 
>in Customer
>5. Using a SQL query too delete all duplicate copies of Customers from 
>Customer table
>6. If this breaks your application in any way, account for that by 
>ensuring that every duplicate record in CustomerB has a primary record in 
>Customer that suffices and returns results. This will ensure that all 
>relations with other models and records are honored.
>7. Update or fix, both models to ensure that duplicates can no longer 
>be inserted
>8. Perform any other schema updates
>
>
>
> On Friday, January 21, 2022 at 12:43:03 PM UTC-7 yebo...@gmail.com wrote:
>
>> Okay bro try this script hope it works
>>
>> On Fri, 21 Jan 2022 at 10:05, jools  wrote:
>>
>>> Dear Django users,
>>>
>>> here’s an interesting case and I’m curious whether somebody can point me 
>>> in the right direction.
>>>
>>> Here’s the problem:
>>> My company has a database of customers. Over the years, many duplicates 
>>> have been created. For cleaning up duplicates, I’d like to have a 
>>> search-and-replace functionality.
>>>
>>> I.e.: Replace all references in the database to customer  with 
>>> customer .
>>> The database schema has quite a bit of complexity, so I’m aiming to find 
>>> a very generic solution.
>>>
>>> Approach:
>>> Django has a bit of functionality to find all references to an existing 
>>> object, namely django.db.models.deletion.Collector and I’m using it to 
>>> find all references.
>>>
>>> Though, the “replace” logic seems quite hard to get right:
>>>
>>>- It has to keep parent links intact
>>>- It has to recognize references in parent models (Customer model is 
>>>derived from the concrete model Actor)
>>>- It has to recognize generic relations, built with Django’s content 
>>>types
>>>
>>>
>>> My stub implementation comes below.
>>>
>>>
>>>- Has anybody else implemented sth like this, e.g. in helper library?
>>>- Do you think the approach is right?
>>>- What would you differently?
>>>- Any caveats that you know of?
>>>
>>> Best regards
>>> Jools
>>>
>>> Stub implementation:
>>>
>>> from django.db.models.deletion import Collector, ProtectedError, 
>>> Res

Re: Lack of tutorials and explanations about channels

2022-01-24 Thread lone...@gmail.com
You and me both are on the same page about documentation about Channels.  I 
tried to follow: Django Channels Tutorial 🔥: the most minimal Real Time 
app (not Chat) | Django WebSockets 
 on YouTube, but I kept 
running into issues.  If you can follow this video, and figure it out, let 
me know if it is missing something.

On Wednesday, November 10, 2021 at 8:48:31 AM UTC-5 Dossou Mawussekuifan 
Gloria Donald KANTI wrote:

> Why aren't there much tutorials and explanations about Channels and 
> websocket integration in django over the internet ? Quite confusing. How 
> can we get to know and understand it more if nobody wants to explain it. I 
> am new to python and drf, wanna implement some realtime features in my app 
> but no chance to get good resources explaining very well how things can be 
> done. If there are some pros here knowing very well about the topic please, 
> write some blog or make some detailed youtube videos to explain the topic. 
> It will really help me and others in the future. It is crucial also for the 
> image of django. Thank you

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


create super user

2022-01-24 Thread Prashanth Patelc
im getting this error
==
match = date_re.match(value)
TypeError: expected string or bytes-like object


this is my user profile model
===

class UserManager(BaseUserManager):
use_in_migrations = True

def _create_user(self, email, password, **extra_fields):
"""
Creates and saves a User with the given mobile and password.
"""
if not email:
raise ValueError('The given email must be set')
# email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user

def create_user(self, email, password=None, **extra_fields):
extra_fields.setdefault('is_superuser', False)
return self._create_user(email, password, **extra_fields)

def create_superuser(self, email, password, **extra_fields):
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault('is_staff', True)

if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')

return self._create_user(email, password, **extra_fields)

class Teams(models.Model):
teamname = models.CharField(max_length=100,unique=True)
team_description = models.CharField(max_length=1024)
def __str__(self):
return self.teamname


class UserProfile(AbstractBaseUser, PermissionsMixin):
id=models.AutoField(primary_key=True)
username = models.CharField(max_length=200, unique=True,
null=True, blank=True)
fullname = models.CharField(_('name'), max_length=200, blank=True,
null=True)
mobile = models.CharField(_('mobile'), unique=True, max_length=10,
blank=True, null=True)
email = models.EmailField(_('email address'),  unique=True,
blank=True, null=True)
password = models.CharField(_('password'),max_length=25,blank=True,
null=True)
date_joined = models.DateTimeField(verbose_name="date joined",
auto_now_add=True,)
is_verified = models.BooleanField(default=True,)
is_active = models.BooleanField(_('active'), default=True)
is_staff = models.BooleanField(_('is_staff'), default=True)
is_admin = models.BooleanField(_('is_Admin'), default=False,
blank=True, null=True)
is_manager = models.BooleanField(_('is_Manger'), default=False,
blank=True, null=True)
is_tl = models.BooleanField(_('is_Tl'), default=False, blank=True,
null=True)
is_agent = models.BooleanField(_('is_Agent'), default=False,
blank=True, null=True)
orginization = models.CharField(max_length=200, null=True, default=False)
dob=models.DateField(default=False)
GENDER_CHOICES = (
('Male', 'Male'),
('Female', 'Female'),
)
Roles = (
('Manager', 'Manager'),
('TL', 'TL'),
('Admin', 'Admin'),
('Agent', 'Agent'),)

gender = models.CharField(max_length=8, choices=GENDER_CHOICES, null=True)
team_name = models.ForeignKey(Teams, on_delete=models.CASCADE,
default=False, null=True, related_name='person_team')
role = models.CharField(max_length=100, null=True, choices=Roles,
default=False)
objects =  UserManager()

USERNAME_FIELD = 'email'  # User should be able to login with
REQUIRED_FIELDS = []

class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')

def get_full_name(self):
'''
Returns the first_name plus the last_name, with a space in between.
'''
full_name = '%s %s' % (self.name)
return full_name.strip()

def get_short_name(self):
'''
Returns the short name for the user.
'''
return self.name

def create_superuser(self, password, email):
"""
Creates and saves a superuser with the given username and password.
"""
user = self.create_user(
email=email,
password=password,
)
user.is_superuser = True
user.is_staff = True
user.save(using=self._db)
return user

remaining models also there with date and time field

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


relations

2022-01-24 Thread frank dilorenzo
I have tried several different ways but I cannot seem to get this right.  
What I have is a list
of suppliers.  Each supplier can have many shipments and each shipment can 
have many species.  Seems simple enough but apparently I must be more 
simple.

I need a suggestion of how to relate these table.

a supplier can have many shipment.  A shipment can have many species.  Any 
help would be appreciated.  Thanks.

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


django module not found

2022-01-24 Thread 'Delvin Alexander' via Django users
Hello,

I am new and just started to learn Django. I am attempting to create my 
first application and ofcourse progress to a website but i am having 
difficulty at the moment. here is whats going on:  

["Import "django.shortcut" could not be resolvedPylancereportMissingImports 

Exception has occurred: ModuleNotFoundError

   - 

No module named 'django.shortcut'
File "C:\Users\delvi\django_project\blog\views.py", line 1, in  
from django.shortcut import render]

I have tried looking online for an answer and still have yet to come to an 
answer that has resolved my issue. I even changed my interpreter, but this 
1 problem still remains. May you someone please 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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f931616a-652f-4ce0-9f8d-32435e9d6e04n%40googlegroups.com.


Re: django module not found

2022-01-24 Thread Lakshyaraj Dash X-D 25
Try restarting your code editor or reinstall python.

On Mon, Jan 24, 2022, 19:28 'Delvin Alexander' via Django users <
django-users@googlegroups.com> wrote:

> Hello,
>
> I am new and just started to learn Django. I am attempting to create my
> first application and ofcourse progress to a website but i am having
> difficulty at the moment. here is whats going on:
>
> ["Import "django.shortcut" could not be resolvedPylance
> reportMissingImports
> 
> Exception has occurred: ModuleNotFoundError
>
>-
>
> No module named 'django.shortcut'
> File "C:\Users\delvi\django_project\blog\views.py", line 1, in 
> from django.shortcut import render]
>
> I have tried looking online for an answer and still have yet to come to an
> answer that has resolved my issue. I even changed my interpreter, but this
> 1 problem still remains. May you someone please 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f931616a-652f-4ce0-9f8d-32435e9d6e04n%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/CAF7qQgBrUTHpaEDhegtCP7ux17%3D6MAELvn_Vxjcv5OV5zThh2w%40mail.gmail.com.


Re: django module not found

2022-01-24 Thread Lakshyaraj Dash X-D 25
If you're using virtual environment then try creating a new virtual
environment and install django again in your virtual environment.

On Mon, Jan 24, 2022, 19:28 'Delvin Alexander' via Django users <
django-users@googlegroups.com> wrote:

> Hello,
>
> I am new and just started to learn Django. I am attempting to create my
> first application and ofcourse progress to a website but i am having
> difficulty at the moment. here is whats going on:
>
> ["Import "django.shortcut" could not be resolvedPylance
> reportMissingImports
> 
> Exception has occurred: ModuleNotFoundError
>
>-
>
> No module named 'django.shortcut'
> File "C:\Users\delvi\django_project\blog\views.py", line 1, in 
> from django.shortcut import render]
>
> I have tried looking online for an answer and still have yet to come to an
> answer that has resolved my issue. I even changed my interpreter, but this
> 1 problem still remains. May you someone please 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/f931616a-652f-4ce0-9f8d-32435e9d6e04n%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/CAF7qQgCwKKpXwwfW2FieP1DLFwX8Ej2pYvqByKP9GWw3wVqnuA%40mail.gmail.com.


Re: django module not found

2022-01-24 Thread Kasper Laudrup

On 24/01/2022 15.11, Lakshyaraj Dash X-D 25 wrote:

Try restarting your code editor or reinstall python.



How would that change anything?

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/72627179-951f-8043-6af5-e06ef684cdc3%40stacktrace.dk.


Re: django module not found

2022-01-24 Thread Kasper Laudrup

On 24/01/2022 05.18, 'Delvin Alexander' via Django users wrote:


No module named 'django.shortcut'


Typo. It should be "django.shortcuts"

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/76039e72-938f-dd96-2947-32a6d16e1b7d%40stacktrace.dk.


Re: django module not found

2022-01-24 Thread Dawda Borje Kujabi
Thank you, it worked.

On Mon, Jan 24, 2022, 2:16 PM Kasper Laudrup  wrote:

> On 24/01/2022 05.18, 'Delvin Alexander' via Django users wrote:
> >
> > No module named 'django.shortcut'
>
> Typo. It should be "django.shortcuts"
>
> 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/76039e72-938f-dd96-2947-32a6d16e1b7d%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/CAFhfAUqX5y9fienJj%2BDwSkcMBSw8wTek0-631isHLnq_fo2MMg%40mail.gmail.com.


Re: Lack of tutorials and explanations about channels

2022-01-24 Thread Steve Smith
I am a huge fan of Django.  But I will agree that the documentation is most 
areas beyond the absolute basics is abysmal.  I have a lot written in Django in 
Class Based Views because I read early on they were the way to go.  I'm not 
going to tell you how much research and time it took me but it was a lot.  
Django is super powerful and it's amazingbut the documentation...while 
maybe better than any other framework is still very lacking for people in my 
humble opinion.  The documentation and books that I've come across are written 
in a way that they assume you already understand it and they pick up from 
there.  Love django.  Agree with the comment about documentation about Channels 
and as I've expressed most of the other documentation as well.




From: django-users@googlegroups.com  on behalf 
of lone...@gmail.com 
Sent: Monday, January 24, 2022 6:03 AM
To: Django users 
Subject: Re: Lack of tutorials and explanations about channels

You and me both are on the same page about documentation about Channels.  I 
tried to follow: Django Channels Tutorial 🔥: the most minimal Real Time app 
(not Chat) | Django WebSockets on 
YouTube, but I kept running into issues.  If you can follow this video, and 
figure it out, let me know if it is missing something.

On Wednesday, November 10, 2021 at 8:48:31 AM UTC-5 Dossou Mawussekuifan Gloria 
Donald KANTI wrote:
Why aren't there much tutorials and explanations about Channels and websocket 
integration in django over the internet ? Quite confusing. How can we get to 
know and understand it more if nobody wants to explain it. I am new to python 
and drf, wanna implement some realtime features in my app but no chance to get 
good resources explaining very well how things can be done. If there are some 
pros here knowing very well about the topic please, write some blog or make 
some detailed youtube videos to explain the topic. It will really help me and 
others in the future. It is crucial also for the image of django. Thank you

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/902feb53-0009-4e5b-946e-4f027daa64a6n%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/CH0PR18MB4292FACCBAC6D6D04DD47D88D25E9%40CH0PR18MB4292.namprd18.prod.outlook.com.


Looking for Recommendations for a Django Photo Gallery

2022-01-24 Thread Mark Phillips
I have been using a very old PHP based photo gallery called Gallery3 as a
photo gallery with about 10 years of photos. Gallery3 is on life support,
so I need to move to something else. I am looking for a simple photo
gallery application that uses file system based storage for the photos.
Gallery3 has all the albums and photos in named directories on the file
system, so I would like, if possible, to have the new photo gallery use the
same directory structure. There are so many django photo galleries that I
am not sure what is good and what isn't.

Thanks for your recommendations!

Mark

-- 
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/CAEqej2NnqwJzQFv%2BrG%2BpTbiiJEBL2yM%3DWxbVi-HnqTmNSVzk4A%40mail.gmail.com.