Jump to content

PrimeMinister

Member
  • Posts

    146
  • Joined

  • Last visited

Everything posted by PrimeMinister

  1. I'm trying to dynamically create and use like and unlike buttons for my cs50w project, which should of course allow the user to like or unlike a post and switch a like button to an unlike button and so on. Now, the infuriating thing is, the like and unlike mechanics themselves work, but the buttons are screwing with me. Either I can't get the opposite button to be created after I deleted the original one via Javascript (I tried to use appendChild and CreateElement, to no avail). Or if a post has more than 1 like then more buttons show up with 2/3 of them being duds, etc. I check in a Django view if the current user has liked any posts (the likes are in their own model with 2 Foreign Keys), then if there are any posts then I send them as context to the necessary templates. Inside the templates themselves, I check if a post corresponds to the context if it does I generate an Unlike button, if not I generate a Like button. I've tinkered and googled but the situation is not improving at all... Code: index.html: {% extends "network/layout.html" %} {{ user.username|json_script:"username" }} {% block body %} <h3 id='greeting'>Brand new posts! Just for you</h3> {% for page in pages %} <div class="card border-primary post"> <h5 class="card-header bg-info user_link">{{page.user.username}}</h5> <div class="card-body"> <div class="card-text border-success" id="content">{{page.content}}</div> {% if user.is_authenticated %} {% if user.username == page.user.username %} <div class="card-text border-success" id='edit-controls'> <textarea id="edit-content"></textarea> <button class="btn btn-primary" id='save-edit'>Save Edit</button> </div> <button class="btn btn-primary edit">Edit Post</button> {% endif %} {% endif %} </div> <div class="card-footer"> <p id='page_id' style="display: none;">{{page.id}}</p> <div class="card-text" id='created_on'>Posted on: {{page.created_on}}</div> <span class="card-text" id='likes'>{{page.likes}} people have liked this</span> {% if user.is_authenticated %} {% for like in liked %} {% if like.liked_post == page %} <span><button class="btn btn-secondary" id="unlike">Unlike</button></span> {% endif %} {% if like.liked_post != page %} <span><button class="btn btn-secondary" id="like">Like</button></span> {% endif %} {% empty %} <span><button class="btn btn-secondary" id="like">Like</button></span> {% endfor %} {% endif %} </div> </div> {% endfor %} <div class="container p-4"> <div class="pagination justify-content-center"> <span class="step-links"> {% if pages.has_previous %} <a href="?page=1">&laquo; first</a> <a href="?page={{ pages.previous_page_number }}">previous</a> {% endif %} <span class="current"> Page {{ pages.number }} of {{ pages.num_pages }} </span> {% if pages.has_next %} <a href="?page={{ pages.next_page_number }}">next</a> <a href="?page={{ pages.num_pages }}">last &raquo;</a> {% endif %} </span> </div> </div> {% endblock %} network.js/liking function function liking() { const divs = document.querySelectorAll(".card-footer"); divs.forEach((div) => { const like_btn = div.querySelector('#like'); const unlike_btn = div.querySelector("#unlike"); const page_id = div.querySelector("#page_id"); if (like_btn !== null) { like_btn.onclick = () => { const like_str = div.querySelector("#likes").textContent; let like_amount = parseInt(like_str.substring(0)); like_amount++; div.querySelector("#likes").textContent = `${like_amount.toString()} people have liked this`; like_btn.remove(); like(page_id.textContent, "like"); }; } if (unlike_btn !== null) { unlike_btn.onclick = () => { const like_str = div.querySelector("#likes").textContent; let like_amount = parseInt(like_str.substring(0)); if (like_amount > 0) { like_amount--; div.querySelector("#likes").textContent = `${like_amount.toString()} people have liked this`; } else if (like_amount === 0) { like_amount = 0; div.querySelector("#likes").textContent = `0 people have liked this`; } unlike_btn.remove(); like(page_id.textContent, "unlike"); }; } }); } like model class Like(models.Model): user = models.ForeignKey(User, on_delete=CASCADE) liked_post = models.ForeignKey(Post, on_delete=CASCADE) def __str__(self): return f"{self.id} - Post {self.liked_post} liked by {self.user}" def is_valid_like(self): return self.user != None and self.liked_post != None django views that I use: def index(request): posts = Post.objects.all().order_by('-id') pages = Paginator(posts, 10) page_num = request.GET.get('page') page_obj = pages.get_page(page_num) try: user_info = User.objects.get(username=request.user.username) except User.DoesNotExist: user_info=None liked_posts = None liked_posts = Like.objects.filter(user=user_info) print(liked_posts) return render(request, "network/index.html", { "pages": page_obj, "liked": liked_posts }) def render_profile(request, username): if request.method == "GET": user_info = None try: user_info = User.objects.get(username=username) except Error: return render(request, "network/notfound.html") posts = Post.objects.filter(user=user_info).reverse() followers = Follow.objects.filter(followee=user_info).count() follows = Follow.objects.filter(user=user_info).count() is_following = True try: Follow.objects.get(user=request.user, followee=user_info) except Follow.DoesNotExist: is_following = False liked_posts = Like.objects.filter(user=user_info) print(liked_posts) JsonResponse({"found": "profile has been found"}, status=200) pages = Paginator(posts, 10) page_num = request.GET.get('page') page_obj = pages.get_page(page_num) return render(request, "network/profile.html", { "username": user_info.username, "pages": page_obj, "followers": followers, "follows": follows, "following": is_following, "liked": liked_posts }) Kind Regards PrimeMinister
  2. Ok, so after scrounging around the internet for help, I got a solution to the problem. Clearing Origin Cache: https://answers.ea.com/t5/Technical...n-t-highlite/m-p/3439987/highlight/true#M6088 Also adding the exe of the game to my antivirus' advanced exceptions helped. After I did these things, the game finally launched.
  3. Hey guys, I'm having a problem with Origin. And what infuriates me most is, is that this problem only affects 2 of my games that require Origin (Star Wars Battlefront 2 and Dead Space 3 respectively). The rest of the games I have that requires Origin to work, works without problems. These 2 games REFUSE to boot/start and to add insult to injury, sometimes via some miracle the games work but then the next time I try to play the game, once again the games refuse to boot... I don't know what I should do anymore. Keep in mind, that I launch all of them from Steam and not Origin itself. What could I do to solve this? Things I've tried: Reinstalling the games Verifying game files Running the EXEs with admin rights Deleting specific things like deleting shader caches, etc and verifying the game files afterwards. Thanks in advance for the help! Kind Regards PrimeSteak
  4. Yeah, seems like the 5500 XT would be the best option for me
  5. Hey guys, I'm in a bit of a predicament. I've looked around a bit on the internet for a graphics card for my new build (includes i5-9400F and 16GB RAM), I just want to game at 1080p on Medium (or Low if it doesn't look like shite). My main problems are the conditions of the cards I got on my shortlist, the pricing and the long-term (meaning I don't want to buy a GPU that I might have to upgrade over the next few years). I'm not sure what to choose. Secondhand (I'm very hesitant on buying used): Gigabyte AORUS RX580 - 4GB - WINDFORCE OC (282 USD) Gigabyte RX480 4GB G1 GAMING (232 USD) ASUS GTX 1060 3GB DUAL (282 USD) MSI GTX1060 GAMING X 6GB (421 USD) New: SAPPHIRE PULSE RX 5500 XT 4GB (297 USD) MSI Radeon RX 5500 XT MECH 4G OC (285 USD) Gigabyte GeForce GTX 1650 D6 EAGLE OC 4GB (280 USD) Gigabyte GeForce GTX 1650 D6 WINDFORCE OC 4GB (282 USD) P.S I'm upgrading from a Gigabyte GTX 750 Ti 4GB OC Windforce, i3-7100 and 8 GB RAM Thanks in advance for the help!
  6. I was considering the Tab A but I hesitated. As long as the new tablet I'm buying is better than a Vodafone Smart Tab 3G (my old tablet from 2012/2013), I'm happy.
  7. Yup, iPad is way out of my budget and well, I tend to have a dislike of Apple products. So an Android tablet would work the best for me, my max budget is R3500 (177 USD).
  8. 7 to 8 inch with a good ppi, I have a Samsung Galaxy A10s, I guess it would be better if it were similar, OS type doesn't matter Did stop by the store closest to me, they only had one tablet, that I couldn't afford
  9. Hey guys, I'm not sure what tablet I can buy that would allow me to read my books (Books I got from Humble Bundle) easily and comfortably, the tablet should be affordable as well. Thanks in advance for the help! Kind Regards PrimeMinister
  10. Well if you're in the market for some JRPGs, then I would definitely recommend the Yakuza series.
  11. Ok, will look into that if I make a build from scratch. So, my last question is, is bottlenecking overrated/overhyped or is it a genuine concern? Cause on another forum I went on, some people kept hammering on bottlenecking cause I have an i3... while others had more or less your take on bottlenecking.
  12. Thx for the advice! I am planning to upgrade to a 6th/7th gen i5 down the line. (but not within the next 6 months to a year)
  13. Tbf I wanna try the XT cause I want to see if AMD lives up to the hype and the card is just under the limit of my budget (R4000, 270 USD ). I'm just worried that the CPU won't work together well with the card and I don't want to waste 270 USD for nothing, ya know?
  14. Hey guys, so I can finally afford to buy a new graphics card but I'm not sure what to buy out of the three options I have: Sapphire Radeon RX 5500 XT Pulse SF 4G (most expensive of the three) Gigabyte GTX 1650 D6 OC 4GB Gigabyte GTX 1050 Ti 4GB (the cheapest of the three) My concerns: My recently bought 21-inch 1080p monitor supports AMD Freesync. But I have an Intel Core i3 - 7100 3.9 GHz, I'm not sure if the CPU might affect things too much. (Please keep in mind, I only want to play at 1080p Medium/High with 30+ FPS.) Thanks in advance for the help! Kind Regards PrimeMinister
  15. Ok, will try this. P.S do I have to make a contract via a lawyer or something or can I do it myself? (just asking)
  16. My mom is the secretary of the club and she asked me if I could make this program. She helped with the rules and she told me what features should be in it. She told the chairman and his wife (my parents are friends with them) that I'm making a program to help with the point keeping. I demoed it to the chairman's wife yesterday and she was very pleased with it. So I only need to demo it to him and the score keeper and I'm home free. But it's very likely at the moment that they will buy it. So to answer your question, I made it to see if I would be capable to be a programmer in future and I made it in the hopes that they would buy it.
  17. So I should give the compiled app I have and the source code? Or what do you mean by this?
  18. It's kind of like a office suite..I'll explain right here The "suite" consists of 3 programs: 1. A login generator for the "main attraction", the point keeping program. To make things a bit more secure, so that the points can't be tampered with so easily. 2. A program that enters the racers that will race in the event into a database, that will then be imported into the "main attraction" itself. 3. The "main attraction", the point keeping program. It's a program that will help the people who have to keep score during the event to be able to keep score more effectively and to modernize the process a bit. The functions in the program include importing the racers, inserting points, editing points, inserting certain codes like DNF, sorting the racers according to certain columns and then exporting the racers and their results to a csv file. That file will then be imported by the score keepers into an excel file.
  19. Hey guys, so I'm going to sell a program I made to the local dirt oval racing club. But I'm not sure what the price should be? I had an idea that I'd want to ask R3000 for it (about 200 USD). Is it too high? Keep in mind, that this is the first program that I ever made at a "professional" scale, I also just recently finished high school. So I don't know if I'm maybe asking too much? If so, what should my asking price be? Thanks in advance for the advice! Kind Regards PrimeMinister
×