Django에서 queryset 및 regex를 사용하여 중복을 찾을 수 있습니까?Django가 queryset 및 regex와 중복을 찾는다
Django select only rows with duplicate field values 는 정규식을 사용하지 않고 보여줍니다
class company(models.Model):
Website = models.URLField(blank=True, null=True)
내가 예를 들어
정규식
와 중복을 찾으려면 :self.values('Website').annotate(count=Count('id')).order_by().filter(count__gt=1)
내가 모델이있다.
Company.objects.create(Website='http://example.com')
Company.objects.create(Website='http://www.example.com')
둘 다 동일한 웹 사이트입니다. 나는 그것이 중복으로 이러한 회사를 반환합니다 있도록 정규식을 사용하고 싶습니다.
정규식을 사용하는 필터가 있다는 것을 알고 있습니다. 내가 정규식을 사용하려면이를 업데이트하는 방법을 잘 모르겠어요 :
self.values('Website').annotate(count=Count('id')).order_by().filter(count__gt=1)
나는 같은 것을 할 싶습니다
Website__iregex='http[s]?://(?:[a-zA-Z]|[0-9]|[[email protected]&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
업데이트를 내가주지 않도록 약간의 혼동이 있었다 보기.
- http://example.org (이름에서 = A)와 이름에서 http://example.org (= 여기 내 DB 내가 뭔가를 반환
Company.objects.all().values('Website').annotate(count=Count('id')).order_by().filter(count__gt=1)
를 호출 할 때
모습입니다 b)Company.objects.create(Website='http://example.com') Company.objects.create(Website='http://www.example.com') Company.objects.create(Website='http://example.org', Name='a') Company.objects.create(Website='http://example.org', Name='b')
example.com과 www.example.com은 동일한 웹 사이트입니다.
example.com과 www.example.com이 동일한 웹 사이트라는 것을 장고에게 알릴 수 있도록 정규 표현식을 사용하고 싶습니다. 그래서
Company.objects.all().values('Website').annotate(count=Count('id')).order_by().filter(count__gt=1)
는 중복 반환 :
http://example.org 및 http://example.org (이름에서 = B)
(이름 = A에서)를
나는 수정할 example.com www.example.COM
이 .annotate (count = Count ('id')). order_by(). filter (count__gt = 1)'전혀 작동하지 않습니까? –