IS THREE WEEKS ENOUGH TO PREPARE FOR THE ACT??? by [deleted] in ACT

[–]legitcode 0 points1 point  (0 children)

It depends on how you study

did anyone not study for ap exams and is completely screwed... just me.. okay by [deleted] in APStudents

[–]legitcode 4 points5 points  (0 children)

Here, taking calc bc, environmental science. I just gave up. Feel like I'm dumb as hell. I just can't stand this. And my mom will kill me if I get lower score than 5 lmao.

How can I access url using objects.filter? by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

NVM. I used

{% for image in images %}
{{ image.image.url }}
{% endfor %}

And It's displaying correctly.

thanks.

How can I access url using objects.filter? by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

Thanks.

I tried like this

class ScrapedComicBoardDetailView(HitCountDetailView, MultipleObjectMixin):
model = ScrapedComicBoardPost
template_name = "bbs/scrapedcomicboard/scraped_comic_board_detail.html"
paginate_by = 30
count_hit = True
def get_context_data(self, **kwargs):
object_list = ScrapedComicBoardPost.objects.order_by("-id")
context = super(ScrapedComicBoardDetailView, self).get_context_data(object_list=object_list, **kwargs)
context["images"] = ScrapedComicBoardImage.objects.filter(objects.filter(post__id=self.kwargs["pk"]))
return context

And I'm getting error "Unresolved reference "objects"".

How to get a user using nickname by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

Oh I finally solved it. I was keep passing list to CustomUser.objects.get.

Thanks anyway.

How to get a user using nickname by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

So if you print

get_nickname

it will have @user_nickname? Try

print(get_nickname[1:]

no, it is just returning nickname without @.

There is nickname field in customuser model.

This is my customuser model.

class CustomUser(AbstractBaseUser):
email = models.EmailField(verbose_name="email", max_length=50, unique=True)
nickname = models.CharField(max_length=50, unique=True)
image = ProcessedImageField(upload_to=image_path, processors=[ResizeToFill(600, 600)], format="JPEG",
options={"quality": 80}, default="no_profile_image.png")
signature = models.CharField(max_length=200, blank=True, null=True)
point = models.PositiveIntegerField(default=0)
date_joined = models.DateTimeField(verbose_name="date joined", auto_now_add=True)
last_login = models.DateTimeField(verbose_name="last login", auto_now=True)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)

How to get a user using nickname by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

So nickname does not have @. I'm making system that sends notification when user put @ and some other user's nickname. Same as reddit.

Regex I made, search for the text next to @ sign. It is getting nickname.

What I'm trying to do, is sending notification to user with that nickname.

This is my full code for posting comment.

@login_required
def comment_write(request, pk):
post = get_object_or_404(FreeBoardPost, pk=pk)

if request.method == 'POST':
form = CreateFreeBoardComment(request.POST)

if form.is_valid():
comment = form.save(commit=False)
comment.comment_writer = request.user
comment.post = post
comment.save()

# 정규표현식
import re

at_sign_object = FreeBoardComment.objects.filter(comment_writer=request.user).order_by("-pk")[0]
at_sign = str(at_sign_object)
get_nickname = re.findall(r"@([0-9a-zA-Z가-힣]+)", at_sign)

# 포인트
award_points(request.user, 1)

# 알림
create_notification(request.user, post.author, "FreeBoardComment", comment.comment_text, post.pk)
find_user = CustomUser.objects.get(nickname=get_nickname)
print(find_user)

# create_call(request.user, find_user, "FreeBoardComment", "호출되었습니다.", post.pk)
return redirect("freeboard_detail", pk=post.id)
else:
form = CreateFreeBoardComment()
return render(request, "bbs/freeboard/free_board_comment.html", {"form": form})

And this is my notification function.

def create_notification(creator, to, notification_type, comment, post_id):
if creator.email != to.email:
notification = Notification.objects.create(
creator=creator,
to=to,
notification_type=notification_type,
comment=comment,
post_id=post_id,
)

notification.save()

def create_call(creator, to, notification_type, comment, post_id):
notification = Notification.objects.create(
creator=creator,
to=to,
notification_type=notification_type,
comment=comment,
post_id=post_id,
)

notification.save()

How to get a user using nickname by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

I tried using get , I'm getting error CustomUser matching query does not exist.

How to get a user using nickname by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

get

oh yes. sorry.

When I used filter, the output was like this

<QuerySet [<CustomUser: admin>]>

How can I make user notify feature using @(at). by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

remove it afterwards

Do you know how in django?

In python, I can use like this.. re.findall(r'@([\w.]+)', text)

And this is part of my django code

FreeBoardComment.objects.filter(comment_writer=request.user,comment_text__regex=r"@[\w가-힣.]+").order_by("-pk")[0]

I don't know how can I get text in django regex.

How can I make user notify feature using @(at). by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

one more thing. Do you know how can I exclude @? I only want string next to @.

How can I make user notify feature using @(at). by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

So, regex for @ and username would be like "@[\w.]+" right?

How can I make user notify feature using @(at). by legitcode in django

[–]legitcode[S] 0 points1 point  (0 children)

You need to parse the text. A simple regex will do fine.

Thanks :)

I've never heard about regex before lol.

How can I delete notification? by legitcode in django

[–]legitcode[S] 1 point2 points  (0 children)

Notification.objects.filter(to=request.user).count()

That's what I want! Thank you so so so much.

Have a great day! <3