MenuAdmin()에 admin.RelatedOnlyFieldListFilter 를 리스트 필터 옵션에 추가해주어 현재 보이는 메뉴와 관련된 해시태그만 필터에 보이도록 수정list_filter = [("hashtags", admin.RelatedOnlyFieldListFilter)]
HashtagAdmin() 에서 get_list_filter() 와 get_list_display()를 사용해서 superuser일 경우 해시태그 작성자가 보이고 그로 필터도 할 수 있도록 했고, staff일 경우 작성자와 해시태그 필터 기능을 모두 삭제함. def get_list_filter(self, request):
if request.user.is_superuser:
list_filter = ("hashtag_author",)
else:
list_filter = ()
return list_filter
def get_list_display(self, request):
if request.user.is_superuser:
list_display = ("hashtag", "hashtag_author", "get_menus")
else:
list_display = ("hashtag", "get_menus")
return list_display
UniqueConstraint를 사용해 hashtag와 hashtag_author의 조합에 대해서 unique할 수 있도록 설정함. 따라서 한 사용자는 중복된 해시태그를 작성할 수 없고 서로 다른 사용자의 경우에는 서로 중복이 되어도 가능함. class Meta:
constraints = [
models.UniqueConstraint(fields=["hashtag", "hashtag_author"], name="unique_hashtag_author")
]
def start_order(request):
return render(request, 'orders/start_order.html')
def face_recognition(request):
# 웹캠 열기
cap = cv2.VideoCapture(0)
if not cap.isOpened():
raise Exception("Cannot open Webcam")
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
# 프레임 읽기
while True:
ret, frame = cap.read()
print("ret>>>>>>>>>>>", ret)
print("frame>>>>>>>>>", frame)
if not ret:
raise Exception("Cannot read frame from webcam")
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
if faces.any():
print("faces>>>>>>>", faces)
break
cap.release()
image_path = "face.jpg"
print("image_path>>>>>>>>>>", image_path)
cv2.imwrite(image_path, frame)
with open(image_path, "rb") as image_file:
encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
print("encoded_image>>>>>>>>>>>", encoded_image)
# base64_image = encoded_image(image_path)
base64_image = f"data:image/jpeg;base64,{encoded_image}"
print("base64_image>>>>>>>>>", base64_image)
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {OPEN_API_KEY}"
}
payload = {
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Although age can be difficult to predict, please provide an approximate number for how old the person in the photo appears to be. Please consider that Asians tend to look younger than you might think.And Please provide an approximate age in 10-year intervals such as teens, 20s, 30s, 40s, 50s, 60s, 70s, or 80s. Please return the inferred age in the format 'Estimated Age: [inferred age]'."
},
{
"type": "image_url",
"image_url": {
"url": base64_image
}
}
]
}
],
"max_tokens": 300
}
print("api통과??>>>>>>>>>>>>")
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
try:
os.remove(image_path)
print(f"{image_path} 이미지가 삭제되었습니다.")
except FileNotFoundError:
print(f"{image_path} 이미지를 찾을 수 없습니다.")
ai_answer = response.json()
age_message = ai_answer["choices"][0]['message']['content']
age = age_message.split("Estimated Age: ")[1].strip()
number = re.findall(r'\d+', age)
age_number = int(number[0])
if age_number >= 60:
return render(request, 'orders/menu_big.html')
return render(request, 'orders/menu.html')
실수로 머지를 하면서 원래 머지 하려던 브랜치가 아니라 다른 브랜치에 머지를 했을 때
git reflog 로 한 번 깃 내역을 확인해주고
git reset --hard head^ 로 가장 마지막 내역을 지워줌
git push -f 로 강제 푸쉬해주면 됨
유의해서 사용할 것!! 튜터님이 알려주신 방법이라 그대로 따라한 것이지만 실제로 내가 그냥 사용하려면 신중해야 할 듯